Filter by Tags

Extern storage class in C

Votes

1

1 0

What is the use of extern storage class in C. When should a programmer use the extern storage class in any program.

Ravinder Singh
Posted on : Mon, Jun 12, 2017
Views : 159
Comments

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Answers (2)


-1

Extern storage class means the variable is defined in a fuction and is used in some other fucntion. it can be overwritten in other functions. "extern" keyword is used to use the variable in fuction other than it is defiend in. It has a predefined value and if not it is initilized with 0.

Below is an Example for Exter variable class:

 

void one(){

       extern int a = 1;

}

void main(){

      extern int a;

      print("%d", a);

}

 

output:1

 

in above example a is an extern variable defiended in function one and used in main fucntion.

 

It is used when a programer wants to share a variable in two or more fucntions.

Sahil Gaba
Mon, Jun 12, 2017
Loading...
Comments

Edit Answer

Submit

-1

Extern storage class in C is declaring a variable inside a function and defining it outside the body of all the functions. 

e.g.

void print()

{

  extern int x;

  printf("%d",x);

}

int main()

{

  extern int x;

  printf("%d",x);

  print();

  return 0;

}

int x=5;

 

output:

55

 

The main purpose of using extern class in C is when you need a single variables to be used in various functions in a program. Only those functions can use the varibales that have declared the variable with the keywoard "extern". 

Apurva Thakker
Mon, Jun 12, 2017
Loading...
Comments

Edit Answer

Submit
This answer will permanently deleted. Do you really want to delete this Answer ?
To Add your Answer Please
LogIn | SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp