what is the variable declaration and variable definition.When is the memory allocated to a variable?
what is the variable declaration and variable definition.When is the memory allocated to a variable?
A declaration lets the compiler know what type the variable is. A definition is a declaration, but a declaration isn't always a definition. A definition allocates storage for the variable and optionally gives it a value.
int i = 0;
Is a definition and
extern int i;
Is a declaration but not a definition and can be placed in the same file as the definition without any adverse effects. A variable can be defined once, but declared any number of times.
Memory is allocated when program execution reaches the definition of a variable.
-Prelude
My best code is written with the delete key.