For the following code
#include <stdio.h>
void f() {
  int x;
  printf("x = %d\n", x);
}
void g() {
  int y = 42;
  printf("y = %d\n", y);
}
int main() {
  f();
  g();
  return 0;
}
I get the following output
x = 22031
y = 42
If I change the order of the last two functions being executed in main() and run the code
void f() {
  int x;
  printf("x = %d\n", x);
}
void g() {
  int y = 42;
  printf("y = %d\n", y);
}
int main() {
  g();
  f();
  return 0;
}
I get the following :
y = 42
x = 42
Can someone explain this to me please.I know it has to do with the way memory is allocated in addresses but I am not sure about the details.
 
    