0
why this output comes 4 and why not -4; #include<iostream> using namespace std; int main() { int a=4; int *p=&a; p-= 8; cout<<a; }
3 Answers
+ 3
p-=8 changes the address of the pointer, not the value of a.
To get -4, replace this line with:
*p -= 8;
+ 1
"P" is a pointer which contains adderss of variable not value of it! By writing "p-=8" you dont even change the address because if address was changed another value would be resualted in output you can simply write a-=8 or *p-=8
+ 1
* means value of to get -4 try
*p-=8; //value of p=p-8;