Here is a C++ program to add/subtract constant value from a pointer
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int x=0,*p;
p=&x;
cout<<"Address in pointer :"<<int(p)<<endl;
p+=10;
cout<<"After addition of 10 in "<<int(p)<<" : "<<int(p)<<endl;
p-=20;
cout<<"After subtraction of 20 in "<<int(p)<<" : "<<int(p)<<endl;
return 0;
}
using namespace std;
int main()
{
int x=0,*p;
p=&x;
cout<<"Address in pointer :"<<int(p)<<endl;
p+=10;
cout<<"After addition of 10 in "<<int(p)<<" : "<<int(p)<<endl;
p-=20;
cout<<"After subtraction of 20 in "<<int(p)<<" : "<<int(p)<<endl;
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment