Why static variable is used in c?



Why static variable is used in c?..

Answer / Archna

In C, static variables are used for several reasons: 1) To retain the value of a variable between function calls. 2) To save memory by reducing the number of copies of the same variable when the function is called multiple times. 3) To create a 'static' array that can hold data after the program terminates, if it's explicitly declared with static storage class.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

write a C code to reverse a string using a recursive function, without swapping or using an extra memory.

9 Answers   Motorola, TCS, Wipro,


What will be the result of the following program? char*g() { static char x[1024]; return x; } main() { char*g1="First String"; strcpy(g(),g1); g1=g(); strcpy(g1,"Second String"); printf("Answer is:%s", g()); } (A) Answer is: First String (B) Answer is: Second String (C) Run time Error/Core Dump (D) None of these

2 Answers   Oracle,


Explain the properties of union. What is the size of a union variable

1 Answers  


write a c program to change only the 3rd bit of the particular number such that other bits are not affected.. if bitnum=10(say.. it can be any no..

10 Answers   Bosch, Mind Tree,


Write a C program where input is: "My name is xyz". output is: "xyz is name My".

1 Answers   TCS,


How can I find the modification date of a file?

1 Answers   Celstream,


Tell me a C program to display the following Output? 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

3 Answers  


Do you know the difference between exit() and _exit() function in c?

1 Answers  


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

0 Answers  


main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k%16 - 10 + 'a' : '\0' ); } while(k /= 16); printf("%s\n", trans); }

4 Answers   Vector,


What is the -> in c?

1 Answers  


Why we use conio h in c?

1 Answers  


Categories