Search This Blog

Saturday, April 7, 2012

Variable


Variable


 A variable is a named memory location in the computer’s memory where different values of a certain type of data can be stored.

Variable Names

In C, a name given to a variable must satisfy the following rules.

 The name can contain letters, digits and the underscore character.

The first character of the name must be an alphabet or an underscore. However the use of
an underscore is not recommended.

 C is case sensitive. So C treats X and x as two different variables.

Keywords cannot be used as variable names

C compilers allow long variable names. However most of the C compilers recognize the first 32 characters.
In C / C++ it is necessary to declare variables before they are used in a program. When a variable is
declared it is designated as belonging to one of the data types used in C. The compiler allocates memory
for the variable according to its data type.

                     Declaration                              Memory Allocation in Bytes
Eg:                     int a;                                                            2
                          char ch;                                                       1
                         float salary;                                                   4

No comments:

Post a Comment