LET US STUDY C PROGRAMMING 2 Variables,keywords
Types of C Variables
In C a quality which may vary during program execution is called a variable. Variable name are names given locations in the memory of computer where different constants are stored. These locations can contain integer, real or character constant. In any language the types of variables that it can support depends on the types of constants that it can handle. This is because a constant stored in a location with a particular types of variable name can hold only that type of constant. For example a constant stored in a memory location with an integer variable name must be an integer constant,one stored in location with a real variable name must be real constant and the one stored in location with a character variable name must be a character constant.
The rules for constructing different types of constants are different However for constructing variable name of all types the same set of rules apply
Rules for constuting variable names
- A variable name is any combination of 1 to 8 alphabets,digit or underscore. Some compilers allow variable name whose length could be up to 40 characters.
- The first character in the variable name must be an alphabet.
- No commas or blanks are allowed within a variable name.
- No special sympol other than underscore can be used in a variable name
- Local variable
Local variables are declared within the body of a function, and can only be used within that function.
- Static variable
Another class of local variable is the static type. It is specified by the keyword static in the variable declaration.
The most striking difference from a non-static local variable is, a static variable is not destroyed on exit from the function.
- Global variable
A global variable declaration looks normal, but is located outside any of the program’s functions. So it is accessible to all functions.
- An example
int global = 10; //global variable
int func (int x)
static int stat_var; //static local variable
int temp; //(normal) local variable
int name; //(normal) local variable
What is C keywords
Keywords are the words whose meaning has already been explained to the C compiler. The keywords canot be used as variable name because if we do we are trying to assign a new meaning to the keyword,which is not allowed by the computer. Some C compilers allow you to construct variable name which is exactly resemble the keywords.
There are 32 keywords available in C Following is the list of keywords in C