0
Plis explain.
int x;=5; int *p=&x; x=x+4; x=*p+4; *p=*p+4; and what will be the output
2 ответов
+ 1
Answer is 17, Assume there is a typo error in 1st statement, so this int x=5;
int x=5; // Declaring int variable and assigned to 5
int*p=&x; // Declaring int pointer and pointing to x
x=x+4; // add 4 to x and assign to x now x is 9=5+4
x=*p+4;// *p is nothing but value of x, so it is 9.
//After this statement x or *p is 13
*p=*p+4; // now *p or x is 13, after this is 17.
So result either x or *p is 17.
Simply pointer variable (p) will point to another variable(x) of same type. Just printing the p will print the address of x. If you want to print the value then use * like *p.
Hope you understand this.
+ 1
thanks