Thursday 15 May 2014

Constants, Variable, Keywords and Data Types

C Keywords 

Keywords are the words whose meaning has already been explained to the C compiler (or in a broad sense to the computer). The keywords cannot be used as variable names because if we do so 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 names that exactly resemble the keywords. However, it would be safer not to mix up the variable names and the keywords. The keywords are also called ‘Reserved words’. Some keywords are:
                                         
DATA TYPES:
    
DATA TYPES describes us which type of data is used and how much memory will allocated for the data. C is rich in data types. The verity of data type allow the programmer to select appropriate data type to satisfy the need of application as well as the needs of different machine.

TYPES:
• Primary Data Type:                                                                                                                                 C compiler support five type of Predefined or fundamental data types:

 


• Derived Data Type:
              Array, pointer, structure and union are called derived data type in C language.

• User Defined Data Type:
            A user can define his her own identifiers to represent a data types. TYPEDEF keyword is used.
                              typedef  data_type  identifier

For more detail please go to the Data Type post or Click Here

Constant:
 
    A Constant is a quantity the value of which will not be changed when the program is being executed. It can be stored in the memory at the specified location. Or we can say that a "constant" is a number, character, or character string that can be used as a value in a program. Use constants to represent floating-point, integer, enumeration, or character values that cannot be modified.
 
There may be a situation in programming that the value of certain variables to remain constant during execution of a program. In doing so we can use a qualifier const at the time of initialization.
 
1.    const float pie =2.14; 2.    const int radius =3; 3.    const char c = 'V'; 4.    const char name[] = "Vishnu";  
When declaring a const variable, it is possible to put const either before or after the type: that is, both  
1.     int const a = 15; 
Or    
1.     const int x = 15; 

In C constant can also be used using preprocessor directive.
 
For example:  #define FIRST_NUMBER 1    // FIRST_NUMBER will be constant throughout the program. 
 
Types of Constants:



VARIABLE:
  
 A variable is a name given to the memory location where the data can be stored and accessed from that location. To indicate the memory location, each variable should be given a unique name called identifier. Variable names are just the symbolic representation of a memory location. Examples of variable name: sum, a_sum, count etc.

Rules for writing variable name in C 
1.    Variable name can be composed of letters (both uppercase and lowercase letters), digits and underscore '_' only.
2.    The first letter of a variable should be either a letter or an underscore. But, it is discouraged to start variable name with an underscore though it is legal. It is because, variable name that starts with underscore can conflict with system names and compiler may complain.
3.    There is no rule for the length of length of a variable. However, the first 31 characters of  a variable are discriminated by the compiler. So, the first 31 letters of two variables in a program should be different.

0 comments :

Post a Comment