C Programming language

C Programming Language: Variables
Previous Home Next

Variable may be change at runtime. A variable data object can be modified.

Types of variables: integer, char, string etc. Each type of variable has their own size and range. For ex. Range of integer is -32768 to 32767 and the range for it is 2, 4 bytes (1 byte = 8 bits). The size of a char is 1 byte. And range is from 1 to 255.

Rules for constructing variable names in C
  • A Variable name is any combination of 1 to 31 alphabets, digits or underscore
  • The first character in variable name must be an alphabet or underscore
  • No commas or blanks are allowed within a variable name
  • No special symbol other than an underscore can be in a variable name


si_int; m_hra; etc

The maximum allowable length of a variable name is 31 character.


Initialization of variable

Initialize a variable in c to assign it a starting value. Without this we can't get whatever happened to memory at that moment.

C does not initialize variables automatically. So if you do not initialize them properly, you can get unexpected results. Fortunately, C makes it easy to initialize variables when you declare them.

int x=45;
int month_lengths[] = {23,34,43,56,32,12,24};
struct role = { "Hamlet", 7, FALSE, "Prince of Denmark ", "Kenneth Branagh"};

Note : The initialization of variable is a good process in programming

Scope and life span of a variable

The area of the program where that variable is valid, the amount of time that a variable is retained, as well as where it can be accessed from, depends on its specified location and type. The life span of that variable, i.e. the length of time that the variable remains in memory.

Previous Home Next