Variable in c language

An entity that may vary during program execution is called a variable. Variable names are names given to locations in memory. These locations can contain integer, real, or character constants.

Consider the following example.

Variable  in C memory

Rules of constucting variable Name:-

  • A variable name is any combination of 1 to 31 alphabets, digits, or underscores. Some compilers allow variable names whose length could be up to 247 characters. Still, it would be safer to stick to the rule of 31 characters. Do not create unnecessarily long variable names as it adds to your typing effort.
  • The first character in the variable name must be an alphabet or underscore ( _ ).
  • No commas or blanks are allowed within a variable name.
  • No special symbol other than an underscore (as in gross_sal) can be used in a variable name.

How to declare variables?

Whatever variable we are going to use in our program at first we need to declare it. Declaration tells the compiler about the type of variable, its range, and operation which can be performed on it.

To declare a variable, write the data type followed by a list of variables of that type:

Data type variable_name1,variable_name2 ..., variable_nameN;

For example:

int a;	
int a,b,c;
float basic_salary,hra,ta,da;