Jun 9 in C++
Q: Difference between Declaration and Definition of a variable.

1 Answer

Jun 10
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.


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.
Click here to read more about C++
Click here to read more about Insurance

Related questions

Jun 19, 2019 in C++
Jun 15 in C++
Jun 11 in C++