What is a variable in C Language

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 in C Language

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



 Declaration of Variables in C Language

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  in C Language

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

Example

 int a=5;

Best Books of C



Spread the love
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
Spread the love