Filter by Tags

Static global variables in C

Votes

0

0 0

What are static global variables in C and how are they different from normal global variables in C ?

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

Ask Question

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

Answers (2)


0

Static global variables are the variables which can be accessed any where in the program and is declared outside all the functions i.e. does not lie in the scope of any function. Since the variables are static the memory allocated is not destroyed till the program is terminated.

e.g.

static int count=0;

static void g1()

{

  printf("%d",++count);

}

static void g2()

{

  printf("%d",count+2);

}

int main()

{

  g1();

  g2();

  g2();

  g1();

  return 0;

}

 

Output:

1356

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

Edit Answer

Submit

-1

Static Global Variables-  value of static global variables stay the same throughout the program as it is defined.

value of normal global variables can be changed anywhere in the program but we can not change values of global static variables.

Sahil Gaba
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