Local Variables

They can be used only within functions. Older C compilers will only accept definitions of local variables BEFORE the first line of code (at the begin of a function). This has been changed with the latest C99 standard. The following modifiers are available:

register

Gives the compiler a hint that this variable will be frequently used in the code (e.g. counter in a loop) and that it should be put into a CPU register (cached) for faster access time. Nowadays compilers do their own performance analysis and will detect the best register use anyway.

static

The variable is declared within a function and would therefore disappear when the end of the function is reached (a stack or automatic variable). But the static keyword make the compiler allocate the variable space NOT on the stack but in persistent memory and the variable will NOT lose its contents between function calls

volatile

A compiler may put a variable into a register or other cache for better access performance. This is OK if there is only one way that this variable can change and the compiler controls it. This is not always true: shared memory e.g. lets variables change from 2 or more processes. The compiler does not know that "behind his back" somebody changes the variable and would still use the stale copy (cached version) of the variable. The volatile keyword forces the compiler to always read the variable fresh from memory.