In this simple C program, when I comment Line Y
and leave Line X
as is, the output of the call to f()
outputs 0
and Line B
outputs some random number. When I comment Line X
and uncomment Line Y
, then the output is some random number because of Line B
and another random number because of Line Y
. However, when I comment Line A
and Line B
, both calls to f()
output 0
. Can someone explain to me why this is the case? Thank you in advance. By the way, I'm using gcc
without any flags and running this on macOS Catalina.
#include <stdio.h>
void f() {
int x;
printf("%d\n", x);
}
int main() {
f(); // Line X
int a; // Line A
printf("%d\n", a); // Line B
f(); // Line Y
return 0;
}