With the following code
#include <stdio.h>
int main() {
int num;
printf("%d\n", num);
int* num2;
printf("%p\n", &num2);
return 0;
}
I got result like:
From Memory allocation for global and local variables,
I know the global variable num
is initialized to 0
implicitly,
even it is not initialized by me.
Now I am just trying something randomly, so I change the code to
#include <stdio.h>
int main() {
int num;
printf("%d\n", num);
int* num2;
printf("%p\n", num2);
return 0;
}
and now I get
Question: I don't know WHY the value of num
is no longer 0
.
In my opinion, what I am doing with the variable num2
and its value HAS
NOTHING TO DO WITH the variable num
.
I am not only interested why, but also want to hear your opinions about this behavior.