Local variables are allocated on the stack
int main(void)
{
int thisVariableIsOnTheStack;
return 0;
}
Variables from the heap are allocated via malloc somewhere in memory. That memory can be returned to the heap, and reused by a later malloc call.
int main(void)
{
char *thisVariableIsOnTheHeap = (char *) malloc(100);
free (thisVariableIsOnTheHeap);
return 0;
}
Module variables are neither. They have a constant address in memory in one module.
void f1(void)
{
/* This function doesn't see thisIsAModule */
}
int thisIsaModule = 3;
void f(void)
{
thisIsaModule *= 2;
}
int main(void)
{
return thisIsaModule;
}
Global variables are neither. They have a constant value in memory, but can be referred to across modules.
extern int globalVariable; /* This is set in some other module. */
int main(void)
{
return globalVariable;
}