What is meant by global static? why we have to use static
variable instead of Global variable

Answers were Sorted based on User's Feedback



What is meant by global static? why we have to use static variable instead of Global variable..

Answer / guest

Static is protected one and you cannot acess the variable
in other files/functions.It is declared in the top of the
file/function.The value retains tho,t the program.

Is This Answer Correct ?    6 Yes 0 No

What is meant by global static? why we have to use static variable instead of Global variable..

Answer / vaibhav

global static means the static value declared as a
global.using this we can share same copy of that variable.

Is This Answer Correct ?    1 Yes 1 No

What is meant by global static? why we have to use static variable instead of Global variable..

Answer / indira amit

Variables defined local to a function disappear at the end
of the function scope. So when we call the function again,
storage for variables is created and
values are reinitialized. So if we want the value to be
extent throughout the life of a program, we can define the
local variable as "static." Initialization is performed only
at the first call and data is retained between func calls.

Had it been gloal variable, it would have been available
outside the scope of the function, but static variable is
not available outside the scope of a function (helpful in
localizing errors - as it can't be changed outside the func
scope).

Is This Answer Correct ?    0 Yes 0 No

What is meant by global static? why we have to use static variable instead of Global variable..

Answer / abdur rab

Static remains throughout the program, however its scope is
limited to that file alone. If a program consists of
multiple files, you want a variable to be seen by the
entire file and do not want that variable to be seen by the
other files, then mark is as static

static int a;

as a global variable

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More C Interview Questions

what is the difference between embedded c and turbo c ?

1 Answers  


Write a code to determine the total number of stops an elevator would take to serve N number of people.

0 Answers   Expedia,


What is #define in c?

0 Answers  


What is the method to save data in stack data structure type?

0 Answers  


Why main function is special give two reasons?

0 Answers  






what is the difference between #include<stdio.h> and #include "stdio.h" ?

3 Answers  


Differentiate between declaring a variable and defining a variable?

0 Answers  


How can I implement a delay, or time a users response, with sub-second resolution?

0 Answers  


FIND THE OUTPUT IF THE INPUT IS 5 5.75 void main() { int i=1; float f=2.25; scanf("%d%f",&i,&f); printf("%d %f",,i,f); } ANSWER IS 5 AND 2.25 WHY?

4 Answers   Wipro,


How to access or modify the const variable in c ?

16 Answers   HCL, HP,


To what value do nonglobal variables default? 1) auto 2) register 3) static

4 Answers  


What are preprocessor directives in c?

0 Answers  


Categories