Here is my code:
int main()
{
int *p;
void *x;
printf("%p\n", p);
printf("%p\n", x);
return 0;
}
which will print:
koraytugay$ ./a.out
0x7fff53b35ad0
0x0
koraytugay$ ./a.out
0x7fff5803fad0
0x0
koraytugay$ ./a.out
0x7fff512c9ad0
0x0
koraytugay$ ./a.out
0x7fff55213ad0
0x0
koraytugay$ ./a.out
0x7fff52dbdad0
0x0
Is there any explanation to this behaviour in the language?
I think, the
C11
standard is quite clear in this regard. Referring chapter 6.7.9, paragraph 10,Now, an indeterminate value is , well, indeterminate (which you're referring to as garbage and / or NULL here). You cannot really know what is going to be there.
EDIT:
Just to clarify, as per the comment,
Right. It seems. It's nothing guaranteed (specified), as far as
C
standard is considered.Just a note: Prefer
int main(void)
overint main()
. The former is recommended.