On a ones-complement platform, what would the following code print?
#include
int main() {
int i = 1, j = -1;
std::cout << i+
First of all, just to clarify thing, crafting a negative zero using bitwise operations and then using the resulting value is not portable. That said, nothing specifies in the documentation of fprintf
(thus, of std::basic_ostream::operator<<(int)
) whether the sign bit in the representation of int corresponds to a padding bit in the representation of unsigned
or an actual value bit.
As a conclusion, this is unspecified behaviour.
#include
int main() {
std::cout << ~0 << std::endl;
return 0;
}