Pointer Arithmetic Operations. The following code shows how to perform arithmetic operation with pointer in C plus plus Programming Language.
Code:
#include<iostream>
using namespace std;
int main()
{
int a = 10, b;
int *p = &a;
// Print Pointer Location and Value
cout << "Changed Location of pointer p is: " << p <<endl;
cout << "Changed Value of pointer p is: " << *p <<endl;
// Print Pointer P+1 Location and Value
cout << "Changed Location of pointer p is: " << p+1 <<endl;
//Increment Pointer value
b = *p + 15;
cout << "Print b: " << b <<endl;
return 0;
}
Output:
Changed Location of pointer p is: 0x7ffee30a9a68
Changed Value of pointer p is: 10
Changed Location of pointer p is: 0x7ffee30a9a6c
Print b: 25