I've been trying to wrap my head around static variables in C and so I wrote this:
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int *pointer;
void stat();
int main()
{
stat();
printf("%i", *pointer);
}
void stat()
{
int c = 2;
pointer = &c;
}
This does work and display 2 in the command line, but I don't understand why. Doesn't int c cease to exist when the function stat exits? Then what does pointer point to? And how does it retain the value of the integer? Why can I do without making int c static here?