Question regarding pointers

say I have defined two pointers as such:

1
2
short* first;
short* second;


will I be able to test for equality as follows:

1
2
3
4
5
6
7
8
if(first == second)
{
cout << "The pointers are the same";
}
else
{
cout << "The pointers are different";
}


will the above code give me the correct result everytime? Will the equality always be true whenever first and second point to exactly the same short datatype, as opposed to two different short datatypes which just happen to equal each other?
Well they aren't point to any value, so yes they will be the same.
Will the equality always be true whenever first and second point to exactly the same short datatype


Yes.

Simple test:

1
2
3
4
5
6
7
8
9
10
11
int a = 5;  // a and b both equal 5
int b = 5;

int* p1 = &a;
int* p2 = &b;

if(p1 == p2)  // FALSE
;

p1 = &b;
if(p1 == p2)  // TRUE 
Thank you
Topic archived. No new replies allowed.