C variables



What is Variable in C Programming

Variable in C Programming is also called as container to store the data. Variable name may have different data types to identify the type of value stored. Suppose we declare variable of type integer then it can store only integer values.Variable is considered as one of the building block of C Programming which is also called as identifier.

[box]A Variable is a name given to the memory location where the actual data is stored.[/box]

Consider real time example , suppose we need to store water then we can store water in glass if quantity of water is small and Bucket is the quantity of water is large. And big can to store water having quantity larger than bucket similarly Variable (i.e Value container) may have different size for storing different verities of values.

Must Read : Fundamental Attributes of Variable

What is Variable in C Programming?

  1. Initially 5 is Stored in memory location and name x is given to it
  2. After We are assigning the new value (3) to the same memory location
  3. This would Overwrite the earlier value 5 since memory location can hold only one value at a time
  4. Since the location ‘x’can hold Different values at different time so it is refered as ‘Variable
  5. In short Variable is name given to Specific memory location or Group.
Constant and Variable in C

Consider following Scenario –

Step 1 : Memory Before Variable Declaration

Initially before declaring variable ,We have Only memory.

Memory is block of bytes.

Each byte is filled with random or garbage data.

Step 2 : Declaring Variable in C Programming

Variable in C Programming
  1. Now we have declared a variable. (in this case we have declared character variable)
  2. Compiler Checks data type . Depending on data type it will allocate appropriate bytes of memory. (in this case Compile will allocate 1 byte because we have declared Character data type)
  3. It’s only declaration so , garbage value inside that address remains the same.

Step 3 : Initialize Variable in C Programming

Variable in C Programming
  1. We have Initialize character variable now.
  2. After initializing value inside that memory block gets overwritten.

Conclusion :

  1. Variable Name always holds a single Value.
  2. Variable Name is user defined name given to Memory Address.
  3. During Second Run , Address of Variable may change.
  4. During second Run , Value set inside variable during current will be considered as garbage..