Saturday, 28 February 2015

           C Programming Variables and Constant Variables

Variables are memory location in computer's memory to store data. 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:  it could be any thing your name ,place name etc. 

    examlpe

    int num; 

 int  is a data type we will discuss about it   in next lesson.

Here, num is a variable of (int) integer type.

Rules for writing variable name in C

  1   Variable name can be composed of letters (both uppercase and lowercase letters), digits             and underscore '_' only.
                EXAMPLE
                 int viVEK;
                     int vivek;
                                int Vivek ;
                  here vivek is a variable  AND  int is a  integer data type
 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   variable name could not start from digit ,it must  start form letter.   

              example 

       int 2vivek;      ->  compiler will give error
                     int vivek2;     ->    no error  
                              int v2vek;    -->  no error
In C programming, you have to declare variable before compiling the program,other wise it will give error.

Constants are the terms that can't be changed during the execution of a program. For example: 1, 2.5, "Programming is easy." etc. In C, constants can be classified as:

Integer constants

Integer constants are the numeric constants(constant associated with number) without any fractional part or exponential part. There are three types of integer constants in C language: decimal constant(base 10), octal constant(base 8) and hexadecimal constant(base 16) .

Decimal digits: 0 1 2 3 4 5 6 7 8 9

Octal digits: 0 1 2 3 4 5 6 7

Hexadecimal digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F.

For example:

Decimal constants: 0, -9, 22 etc
Octal constants: 021, 077, 033 etc
Hexadecimal constants: 0x7f, 0x2a, 0x521 etc

Floating-point constants


Floating point constants are the numeric constants that has either fractional form or exponent form. For example:

-2.0
0.0000234
-0.22E-5

Note:Here, E-5 represents 10-5. Thus, -0.22E-5 = -0.0000022.

Character constants


Character constants are the constant which use single quotation around characters. For example: 'a', 'l', 'm', 'F' etc.


No comments :

Post a Comment