Sail E0 Webinar
Question


What is the output of the following program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int x = -1;
6.
unsigned int y = 2;
7.
8.
if(x > y) {
9.
cout
Options:
A .  x is greater
B .  y is greater
C .  Implementation defined
D .  Arbitrary
Answer: Option A

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



Was this answer helpful ?

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers