The program that I wrote is :
char* str_1;
void main()
{
char* str_2;
printf("STR_1 Address of pointer : %p\n", &str_1);
printf("STR_2 Address of pointer : %p\n", &str_2);
printf("STR_1 pointer : %p\n", str_1);
printf("STR_2 pointer : %p\n", str_2);
}
And the output is the following :
STR_1 Address of pointer : 00404048
STR_2 Address of pointer : 0028FF1C
STR_1 pointer : 00000000
STR_2 pointer : 7EFDE000
How can we explain this ?
Variables defined at namespace scope are value-initialized by default, that's why str_1 points to NULL.
str_2 is not initialized, so the line
printf("STR_2 pointer : %p\n", str_2);
is actually undefined behavior. A garbage value is printed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With