Home » C++ Programming » Data Types » Question
  1. What is the output of the following program?
    #include
    using namespace std;
    int main()
    {
    int a = -10;
    unsigned int b = 20;

    if(a > b)
    {
    cout << "a is greater";
    }
    else
    {
    cout << "b is greater";
    }
    return 0;
    }
    1. 10
    2. 20
    3. a is greater
    4. b is greater
    5. None of these
Correct Option: C

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



Your comments will be displayed only after manual approval.