Consider the output of this code:
char A = 'a';
char B[] = "b";
cout<<&A;
It outputs "ab" (the concatenation of A and B) and I wonder why. Please, explain me this.
Because &A is a char *. A string, represented by a char *, is required to have a '\0' terminating byte.
&A points to a single char, without a following '\0'. As such, attempting to print this text string results in undefined behavior.
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