I thought the local variable in C was 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, partial result:
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
Can anyone explain this? Or refer to the standard link that C will not trigger local vars?
source
share