Variable declarations and datatypes

Home / Uncategorized / Variable declarations and datatypes

Question:
In the following statements first three are definitions and the last one is the declaration:auto int i;

static int j;

register int k;

extern int l;
What’s the reason for the same?


Answer:
In first three(int i, static int j, register int k) is a definition. It denotes the space for the integer to be in this translation unit and advices the linker to link all references to i against this entity. If you have more or less than exactly one of these definitions, the linker will complain.

But in last extern int l, is a declaration, since it just introduces/specifies l, no new memory address/space is allocated. You can have as many extern int l in each compilation unit as you want. A declaration introduces names into a translation unit or redeclares names introduced by previous declarations.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *