Google News
logo
Embedded C - Interview Questions
Why do we use 'static' variable in C?
The purposes to use a static variable are :
 
* A static variable does not redeclare that means if it is declared in a function it will not redeclare on each function call, therefore, static is able to maintain the value.

* Its scope is local but it is live until the end of the program.

* Generally, it is used to count something, for example, there is function openBakAccount() which calls every time when a new account opens in the bank. Then, to count the total number of the opened account, we can declare a static variable in the function and can increase it on each function call.
Advertisement