Variable in C

Variable in C




  • Variable is a named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable. Different types of variables require different amounts of memory. The value of the variable may get change in the program

  • Variable Declaration:


Datatype variable_name;

or for multiple variable declarations of same

Data type use

Datatype variable_1, variable_2, variable_3;

  • When variables are declared the garbage value is assigned to it according to is datatype.

  • Difference between variable declaration and definition.

  • Variable declaration refers to the part where a variable is first declared or introduced before its first use. Variable definition is the part where the variable is assigned a memory location and a value.

  • Howhere the declaration and definition are done together.


#include<stdio.h>

int main()

{

// declaration and definition of variable

char name='A';

float total_amount;


//This is both declation and definition of total_amount variable is allocated memory assigned garbage value.


printf("%f",total_amount);


}

Output:  garbage value

  • Garbage value are just random stuff left over in memory so when you try access them variable or by memory addresses You get some random value.