I'm writing some code and find this issue. I'm curious about why does this happen.
The code is as follows:
int n = sizeof(int)*8;
int mask_two = (-1<<n);
cout<<"1:"<<hex<<mask_two<<endl;
int y = -1<<(sizeof(int)*8);
cout<<"2:"<<hex<<y<<endl;
When I compile this code, the output is:
1:ffffffff
2:0
Why are the ouput #1 and output #2 not the same value? The compile is Visual C++ 10.0. What is the root cause of this problem?