I write a code (in my Windows 11, with Embarcadero C++ and using GNU G++17) as follows:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cout<<&a+1<<endl<<&b<<endl;
cout<<(&a+1==&b)<<endl;
return 0;
}
I suppose that, if &a+1
and &b
gives the same address value, the statement &a+1==&b
will returns 1
. However, it returns a 0
.
0x78fe1c
0x78fe1c
0
To clarify this issue, I added some lines of code.
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cout<<&a+1<<endl<<&b<<endl;
cout<<(&a+1<=&b)<<endl;
cout<<(&a+1>=&b)<<endl;
cout<<(&a+1==&b)<<endl;
cout<<(&a+1!=&b)<<endl;
return 0;
}
But the result becomes more confusing:
0x78fe1c
0x78fe1c
1
1
0
1
It means that, &a+1
is no more than &b
and no less than it. In the meantime they are not equal. But why?