#include <iostream> using namespace std; int main() { int x = -1; unsigned int y = 2; if(x > y) { cout << "x is greater"; } else { cout << "y is greater"; } }
a) x is greater
b) y is greater
c) implementation defined
d) arbitrary
#include <iostream> using namespace std; int main() { int x = -1; unsigned int y = 2; if(x > y) { cout << "x is greater"; } else { cout << "y is greater"; } }
a) x is greater
b) y is greater
c) implementation defined
d) arbitrary
You must be logged in to post a comment.
a
Explanation: x is promoted to unsigned int on comparison. On conversion x has all bits set, making it the bigger one.