What will be the output of the following C++ code?

#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

1 thought on “What will be the output of the following C++ code?”

  1. a
    Explanation: x is promoted to unsigned int on comparison. On conversion x has all bits set, making it the bigger one.

Leave a Comment