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
00EFF680
for everytime I compare the adresssp
with another pointer. - I get an answer of
00EFF670
for everytime I compare the address ofq
with another pointer. - I get an answer of
15726208
when I look at the pointer value ofp
. And I get an answer of
15726212
When I look at the pointer value ofp + 1
.I get an answer of
15726192
when I look at the pointer value ofq
- And I get an answer of
15726200
Wehn 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;
}