Ads block

Banner 728x90px

Variables

A variable is a container that contains or stores data. It is a way to naming the memory location, where data is stored. Once a variable became declared, then it can be accessed multiple time in the program.

The value assigned to variable can change during the execution of the program.Here is syntax to declare a variable.

data type variable_name;

Some rules to declare a variable

  • A variable can have alphabets, digits, and underscore.
  • A variable name can start with the alphabet, and underscore only. It can't start with a digit.
  • No whitespace is allowed within the variable name.
  • A variable name must not be any reserved word or keyword, e.g. int, float, etc.
VariablesDescription
Localthat are recognized only within a single function.
Globalthat are recognized in two or more function.

There are two different way to identify a variable.

  • Through Data type
  • Through Storage class

We use data type before the variable's name. Data type identify which type of data item is going to be stored in the variable.

Let's take some examples of variable declaration.



In the next section we will know about storage class in detail.