Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Basics of C Programming
  5. Storage Classes
  6. Extern Storage Class

Extern Storage Class

Extern Storage Class

  • Identifiers declared in the global scope by default have extern storage class
  • We can also access extern variables of one file to another file. But make sure both files are in same folder.
  • extern variable cannot be initialized if a declaration statement is written within the block or local scope
  • The extern storage class specifier cannot be used in the parameter declaration either in the function declaration or in the function definition

Example

#include<stdio.h>
#include<conio.h>
extern int a=200;
int main()
{
	printf("a = %d\n",a);
	return 0;
}

Output

C:\TDM-GCC-64>gcc extern.c -o extern
extern.c:3:12: warning: 'a' initialized and declared 'extern'
 extern int a=200;
         ^
C:\TDM-GCC-64>extern
a = 200

Views: 3

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments