Heap vs Stack: read here.
In C, static variables are preceded by the static keyword. Their values are persisted beyond their visibility scope. They would keep their values between the execution of the same function.
Consider the following function. Run it and see that Foo() is called only once every time as the variable count is re-initialized and created every time Foo is called. This is a dynamic vairable.
If you uncomment the static keyword you'll see that the value of count is kept and not set back to 1 every time Foo() is called. This is a static variable.
#include <stdio.h>
void Foo()
{
/*static*/ int count = 1;
printf("Foo has been called %d times\n", count);
count++;
}
int main()
{
Foo();
Foo();
Foo();
return 0;
}
You would normally use dynamic variables. Their life span should be limited to their scope (the Foo() function in the above example, normally between an opening and closing curly brace). But you might want the variable to survive even beyond the scope, then you use static.
I hope this helps.