+ 7
How do we arrive at 26 as answer here? int a = 10; int b = 13; int *p1= &a; int *p2= &a; *p1 = b; cout << (*p1) + (*p2);
I failed this question in a challenge, hoping the community can shed light.
6 Answers
+ 6
a = 10
b = 13
*p1 = &a - > store address of a
*p2 = &a - > store address of a
*p1 = b - > the value of a is now equal to the value of b
cout << *p1 + *p2; - > p1 and p2 point to a, the Asterix means take the value at address of a (so 13)
So 13 + 13 = 26
+ 4
Ah I see! So since pointer *p1 has now been assigned value of 13, which replaces the 10, and because all the two pointers point to same value of 13, the operation (*p1)+(*p2)= 26.
Thanks a lot!
+ 1
You're welcome!
+ 1
Hii
0
why value two not equal to one
0
(*p2)+(*p1)=20
so 10 +10 why not.why first like two 10 13 is 13+13 why not 13 to 10 like 10 +10