What does static variable mean in C?

What does static variable mean in C?

Static variable is available to a C application, throughout the life time. At the time of starting the program execution, static variables allocations takes place first. In a scenario where one variable is to be used by all the functions (which is accessed by main () function), then the variable need to be declared as static in a C program. The value of the variable is persisted between successive calls to functions. One more significant feature of static variable is that, the address of the variable can be passed to modules and functions which are not in the same C file.

static is an access qualifier that limits the scope but causes the variable to exist for the lifetime of the program. This means a static variable is one that is not seen outside the function in which it is declared but which remains until the program terminates. It also means that the value of the variable persists between successive calls to a function. The value of such a variable will remain and may be seen even after calls to a function. One more thing is that a declaration statement of such a variable inside a function will be executed only once.
Differences between structures and arrays
The following are the differences between structures and arrays: Array elements are homogeneous. Structure elements are of different data type....
Define macros. Advantages and disadvantages of Macros
A macro is a name given to a block of C statements as a pre-processor directive...
Pass by reference vs. pass by value
Pass by value always invokes / calls the function or returns a value that is based on the value....
Post your comment
Discussion Board
Comment*
Great.
Aryan 07-12-2015
datastructures
very interesting
srikanth 02-14-2014