I thought that the local variable in C is not initialized. But when I compiled this code with gcc.
void f() {
static int s;
int n;
printf("static s = %d\n", s++);
printf("local n = %d\n", n++);
f();
}
main() {
f();
}
And run this code, the partial result is:
static s = 0
local n = 0
static s = 1
local n = 0
static s = 2
local n = 0
static s = 3
local n = 0
static s = 4
local n = 0
static s = 5
local n = 0
...
static s = 261974
local n = 0
static s = 261975
local n = 0
static s = 261976
local n = 0
static s = 261977
local n = 0
static s = 261978
local n = 0
static s = 261979
local n = 0
static s = 261980
local n = 0
static s = 261981
local n = 0
Segmentation fault: 11
Could anyone please explain this? Or refer to a standard reference that C won't init local vars?