+ 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;
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
+ 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
+ 3
@Oma Falk thank you
+ 2
@GAWEN thank you alot, yes now i got the result is 9 :)
+ 2
thank u
+ 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.