could someone tell me why would the result of *p=*p+4 eqal to 17 ????!!! help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

could someone tell me why would the result of *p=*p+4 eqal to 17 ????!!! help

int x = 5; int *p = &x; *p = *p + 4;

26th Dec 2017, 9:14 AM
RiGeL
RiGeL - avatar
7 Answers
+ 9
Actually the que. u r referring is this:--😊 #include <iostream> using namespace std; int main() { int x = 5; int *p = &x; x=x+4; //x=5+4=9 therefore *p=9 x=*p+4;. // x=9+4=13 therefore *p =13 *p = *p + 4;. // finally *p= 13+4 = 17 cout<< *p; } this outputs :- 17 😊😊😊 ..I hope this helps
26th Dec 2017, 12:53 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 6
int x = 5; //assigned 5 to x int *p = &x; *p = *p + 4; //*p is a pointer to an integer value x so the address of x is assigned to the integer pointer //*p take the value which is present at the address of x which is 5 so int *p=5 now in next step *p=*p+4; so *p=5+4=9 and the output came as 9
26th Dec 2017, 9:22 AM
GAWEN STEASY
GAWEN STEASY - avatar
26th Dec 2017, 9:24 AM
Oma Falk
Oma Falk - avatar
+ 3
@Oma Falk thank you
26th Dec 2017, 9:52 AM
RiGeL
RiGeL - avatar
+ 2
@GAWEN thank you alot, yes now i got the result is 9 :)
26th Dec 2017, 9:52 AM
RiGeL
RiGeL - avatar
+ 2
thank u
30th Dec 2017, 5:13 PM
Kalpana Reddy
+ 1
This really shouldn't come out as 17. Was it from a challenge question or from code playground? If it's from code playground, post your code here.
26th Dec 2017, 9:29 AM
BlazingMagpie
BlazingMagpie - avatar