elibraryportal Logo

Variables in C

Variable is a name of the memory location which store data in variable whose value can be changed at the execution time of program.

Some Rules for defining variables

  • variable may have alphabets, digits, and underscore.
  • variable name can start with the alphabet, and underscore only. It can't start with a digit.
  • No space is allowed within the variable name.
  • Variable name must not be any reserved word or keyword, e.g. int, float, etc.

Valid variable names:

Invalid variable names:

Types of Variables in C

There are Five types of variables in c:

  1. Local variable
  2. Global variable
  3. Static variable
  4. Automatic variable
  5. External variable

1) Local Variable

Local Variable that is declared inside the function or block.

It must be declared at the start of the block.

You must initialize the local variable before .

2) Global Variable

Global Variable that is declared outside the function or block. Any function can change the value of the global variable.

Global Variable declared at the start of the block.

3) Static Variable

Static Variable that is declared with the static keyword..

4) Automatic Variable

Automatic Variable explicitly declare an automatic variable using auto keyword.

5) External Variable

You need to use extern keyword.It is flow the global globa


Next TopicData Type in C