Declaration of variables

In C plus plus  (as in many other programming languages) all the variables that a program is going to use must be declared prior to use. Declaration of a variable serves two purposes:
It associates a type and an identifier (or name) with the variable. The type allows the compiler to interpret statements correctly. For example in the CPU the instruction to add two integer values together is different from the instruction to add two floating-point values together. Hence the compiler must know the type of the variables so it can generate the correct add instruction.
It allows the compiler to decide how much storage space to allocate for storage of the value associated with the identifier and to assign an address for each variable which can be used in code generation.
    Difference of Defining & Declaring a variable
    Variable Definition specify the name and the type of the variable and also set aside memory space for the variable. A variable Declaration by contrast, specifies the variable’s name and data type but doesn't set aside any memory for the variable.
    In most cases the word “Declaration” is used for both meaning. 

    Posted by IRFAN Saturday, April 3, 2010

    0 comments

    Post a Comment