0 votes
in C Plus Plus by
Difference between Declaration and Definition of a variable.

1 Answer

0 votes
by
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.

Related questions

+2 votes
asked Jun 19, 2019 in C Plus Plus by anonymous
+2 votes
0 votes
asked Jun 15, 2020 in C Plus Plus by Robindeniel
...