I want to compare the memory address and pointer value of p, p + 1, q , and q + 1.
I want to understand, what the following values actually mean. I can't quite wrap my head around whats going on.
When I run the code:
- I get an answer of
00EFF680for everytime I compare the adressspwith another pointer. - I get an answer of
00EFF670for everytime I compare the address ofqwith another pointer. - I get an answer of
15726208when I look at the pointer value ofp. And I get an answer of
15726212When I look at the pointer value ofp + 1.I get an answer of
15726192when I look at the pointer value ofq- And I get an answer of
15726200Wehn I look at the pointer value ofq + 1.
Code
#include <iostream>
#include <string>
using namespace std;
int main()
{
int val = 20;
double valD = 20;
int *p = &val;
double *q;
q = &valD;
cout << "Memory Address" << endl;
cout << p == p + 1;
cout << endl;
cout << q == q + 1;
cout << endl;
cout << p == q;
cout << endl;
cout << q == p;
cout << endl;
cout << p == q + 1;
cout << endl;
cout << q == p + 1;
cout << endl;
cout << "Now Compare Pointer Value" << endl;
cout << (unsigned long)(p) << endl;
cout << (unsigned long) (p + 1) << endl;
cout << (unsigned long)(q) << endl;
cout << (unsigned long) (q + 1) << endl;
cout <<"--------" << endl;
return 0;
}
