Course Content
Programming in C
About Lesson

A variable of function can be declared static using the keyword static. If an external variable or a function is declared static, it limits the scope of that variable or function to the file where its defined. They can not be accessed from other files.

static int stack[MAX];
static int top;

static void printall(int [], int);

In the above example, variables stack and top as well as printall function can only be accessed from the same file.

We could also make internal variables static. Internal static variables are local to a function, similar to automatic variables, but unlike automatic variables, they remain in existence even after the program control exits the function. So, they preserve their value in between function calls. Static variables are initialised to zero by default.

Scroll to Top