Friday, December 6, 2013

Difference between declaration and definition

Declaration
-----------------
      Declaration tells the type of the variable only. That is , it tells whether it is an int or a float or a char. But, the space needed for the variable is not allocated during declaration.
int a;
After this statement, the compiler knows that there is going to be a variable a of type 'int'. But no space is allocated.


Definitionl
--------------
        Space is allocated for the variable and some initial value is assigned.
int a=50;
Variable a is initialised and assigned a value. Only during this definition, space for the variable is allocated.

Note
--------
Redefinition is an error but redeclaration is not an error.



No comments:

Post a Comment