char str[] = "some short string";
int a = 20;
strcat(str, "a very very long string");
printf("%d\n", a); // prints 20
If I understand correctly, a
is added to the stack directly above str
. But this should mean that when str
is resized to take up more space, it should overwrite the memory space a
is using. How does this still print 20?