+ 5
Why the output is 'c', can anyone say me?
const char *p="12345"; const char **q=&p; *q="abcde"; const char *s=++p; p="UVXYZ"; cout<<*++s;
5 Answers
+ 5
0. p holds address of constant "12345"
1. q holds address of p.
So now *q = p = &("12345")
2. Change *q to hold address of constant "abcde"
This also replaces p, so now p holds the same address [&("abcde")].
3. Increment p to address of constant "bcde"
4. Assign s = p = address of constant "bcde"
5. Change p to hold address of constant "UVXYZ"
6. Increment s to address of constant "cde"
7. Output the const char pointed to by s, which is 'c'.
+ 4
You are welcome! đ€
+ 3
Ok thank you Brian
+ 2
Nikhil Maroju, Step 5 begins with both p and s holding duplicate copies of the memory address where "bcde" is located. Then p gets reassigned to hold a different address where "UVXYZ" is stored. The address stored in s does not change, and the constant that it points to does not change.
+ 1
Hey thank you Brian ,
But at 5th step we are changing p to hold address of constant "UVWYZ" so 's' value should be changed right!, As s is holding same address