4 Years
Discussion Span
Last Post by Neelam_1

But sir ..on google I read it that if no storage class is mentioned than bydefault global variable are of extern linkage.

" If you do not specify a storage class (that is, the extern or static keywords), then by default global variables have external linkage. From the C99 standard"


If you know that all global variables, with no storage class mentioned, are

1) kept until the end of the program.


2) available to your program in any function, without using a parameter.


3) may be overshadowed or covered, by a local variable with the same name, in that function.

What else is there that you need to know, exactly?

Edited by Adak


Sir what is troubling me is that ..somewhere it is mentioned that global are static bydefault that means they are available within a file...but somewhere it's mentioned that global variable have external linkage by default..if static is not mentioned.

Sir I'll be very helpful if you make me understand this concept.


The quote you posted does NOT say globals are static by default, it says just the opposite. "external linkage" means that if there are two *.c files, say A.c and B.c, a global variable declared in A.c can be used in B.c. In B.c you declare the variable as extern.

Example use:


#include <stdio.h>

int MyGlobal = 123;

int main()




#include <stdio.h>

extern int MyhGlobal;

void foo()
   printf("%d\n", MyGlobal);

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.