Google News
logo
CPP - Interview Questions
Difference between Declaration and Definition of a variable.
The declaration of a variable is merely specifying the data type of a variable and the variable name. As a result of the declaration, we tell the compiler to reserve the space for a variable in the memory according to the data type specified.
 
Example :
int Result;
char c;
int a,b,c;
All the above are valid declarations. Also, note that as a result of the declaration, the value of the variable is undetermined.
 
Whereas, a definition is an implementation/instantiation of the declared variable where we tie up appropriate value to the declared variable so that the linker will be able to link references to the appropriate entities.
 
From above Example,
Result = 10;

C = ‘A’;
These are valid definitions.
Advertisement