What is a variable in C Language

Preview

What is a variable in C Language

A variable may be defined as a named memory location. The value of a variable can vary during the execution of a program.



Rules to name a variable in C Language

There are few basics rules which must be kept in mind while defining a variable. They are as follows:-

  1. Both digits and alphabets are allowed while naming a variable.
  2. Capital letters and small letters are treated differently.
  3. First character must be an alphabet or underscore.
  4. Variable name can contain digits only after first character.
  5. Keyword can’t be used to name a variable.
  6. No special character other than underscore can be used.
  7. It can’t contain spaces.

Examples of invalid variable names

155First character can’t be a digit.
intIt is a keyword of C.
{areaoftriangle}Special characters other than underscore are not allowed.
f nameVariable name can’t contain a space.
first-nameSpecial character other than underscore are not allowed.
4thFirst character can’t be a digit.



 Declaration of Variables

The syntax for declaring a variable is  <data-type> variable-1,variable-2,variable3;

Example:

 int number;            

Above statement declares a variable named number of int type.

Initialization of Variables  

Initialization refers to assigning some value to a variable during declaration of variable.

Example

 int a=5;

Best Books of C



Lesson tags: C variables, declaration of C variable, rules to name a variable in c language, What is a variable
Back to: C Programming Language