I am confused after listening to audio about declaration and definition.
first : int x; —> is declaration or definition?
if int x; written globally then int x; is declaration or definition?
if int x; is with the context or with in the main() program then int x is declaration or definition.
please clarify me sir.
when we will call declaration….?
when we will call definition….?
what is extern int x; is called ….?
regardless of where it is used, is both a declaration ( i.e. x is a reference that always behaves likes an int ) and a definition ( i.e. the needed bytes for x are made available ). When an extern prefix is used, the statement is stripped off the definition part; it still retains the declaration part.
When used inside a context, the memory needed for x will be made available in stack ( everytime the CPU enters the context ) ==> multiple copies of x are possible if the context is inside a recursively invoked function.
When used globally, the compiler itself allots memory needed for x and it is available from the beginning of execution period till the end.
When static prefix is used, ( and extern prefix is not used ) only the access of the variable x is affected. The other characteristics remain the same.
A complete understanding of this is possible after the Session 18 thru Session 22 on Compilation is completed.
Please login first to submit.