What is Variable?

365 views.

A variable is a name given to a memory location where we can store some data.

Variable Declaration

The process of specifying what type of data stored into the memory is called as variable declaration.

Syntax

Example

When a variable is declared, the memory for that will be allocated. The amout of memory allocated to a variable will depend upon the data type is specified. Once the memory for that variable is allocated and if we do not specify any value to that variable, then the variable will automatically contain its default value.

Byte 0
Short 0
Int 0
Long 0
Float 0.0
Double 0.0
Char Space
Boolean false

If we declare a variable and if do not provide a value to that variable then that variable will be initiated automatically with default values. If we do not want the variable to contain default values, then we can initialize the variable with our own values.

Syntax for initialing a variable during declaration time:

 

Example:

 

Initialization

The process of specifying a value to a variable for the first time is called initiation.

The value of a variable can be changed any number of times during the execution of the program.

Assignment:

The process of specifying a value to a variable from the second time onwards or after the initialization is called assignment

 

Example:

 

 

 

 

Leave a Reply