Variables in C

While programming, we very often need to access the memory to read and write data.

The memory addresses are hexadecimal values.

So, it is very hard to keep track of hexadecimal values while programming.

To manipulate memory address easily, we can attach a variable name to the memory address.

So, it will be very easier to manipulate the memory address using a variable name rather than hexadecimal values.

Pictorial Explanation

variables in C

In the above diagram, memory address 22fe4c has mapped with the variable name letter.

Using variable letter, we can easily manipulate the memory address 22fe4c.

Similarly, using variable letter2, we can easily manipulate the memory address 22fe4d.




Valid variable names in C

1. Variable name should start with letter(a-zA-Z) or underscore (_).

Valid

age

_age

Age

Invalid

1age


2.In variable name, no special characters allowed other than underscore (_).

Valid

_age

age_

Invalid

age_*

+age


3.Variables are case sensitive.

age and Age are different, since variable names are case sensitive.


4.Variable name can be constructed with digits and letters.

Example

Age1

Age2


5.Variable name should not be a C keyword.Keywords are also called as reserved words.

Example

int, main are reserved for special meaning. So, we should not declare keyword as a variable name.