Cannot (again) assign correct value to signed short
Why this gives zero as an output? I suspect some compile开发者_高级运维r work in it but why?
signed int sint_ = numeric_limits<signed int>::min() << '\n';
cout << "signed int: " << sint_ << '\n';
This is because of the accidental << '\n'
on the first line. Its effect is to left shift the bits of the minimum value by 13 positions (13 being the character code of \n
). Since the bit pattern of the most negative value is 1000...0
, the result becomes 0.
signed int sint_ = numeric_limits<signed int>::min() << '\n';
What is this \n
at the end?
Is this not what you want:
signed int sint_ = numeric_limits<signed int>::min();
?
Demo : http://ideone.com/aOXGH
精彩评论