Home / CSE MCQs / C-MCQs :: Conditional Expressions

CSE MCQs :: C-MCQs

  1. What is the output of this C code?

    int main()
    {
    int x = 1;
    int y = x == 1 ? getchar(): 2;
    printf("%d\n", y);
    }
  2. A.
    Compile time error
    B.
    Whatever character getchar function returns
    C.
    Ascii value of character getchar function returns
    D.
    2

  3. What is the output of this C code?

    int main()
    {
    int x = 1;
    short int i = 2;
    float f = 3;
    if (sizeof((x == 2) ? f : i) == sizeof(float))
    printf("float\n");
    else if (sizeof((x == 2) ? f : i) == sizeof(short int))
    printf("short int\n");
    }
  4. A.
    float
    B.
    short int
    C.
    Undefined behaviour
    D.
    Compile time error

  5. What is the output of this C code?

    int main()
    {
    int a = 2;
    int b = 0;
    int y = (b == 0) ? a :(a > b) ? (b = 1): a;
    printf("%d\n", y);
    }
  6. A.
    Compile time error
    B.
    1
    C.
    2
    D.
    Undefined behaviour

  7. What is the output of this C code?

    int main()
    {
    int y = 1, x = 0;
    int l = (y++, x++) ? y : x;
    printf("%d\n", l);
    }
  8. A.
    1
    B.
    2
    C.
    Compile time error
    D.
    Undefined behaviour

  9. What is the output of this C code?

    void main()
    {
    int k = 8;
    int m = 7;
    int z = k < m ? k++ : m++;
    printf("%d", z);
    }
  10. A.
    7
    B.
    8
    C.
    Run time error
    D.
    None of the mentioned.

  11. Comment on the output of this C code?

    void main()
    {
    int k = 8;
    int m = 7;
    int z = k < m ? k = m : m++;
    printf("%d", z);
    }
  12. A.
    Run time error
    B.
    7
    C.
    8
    D.
    Depends on compiler

  13. The code snippet below produces

    void main()
    {
    1 < 2 ? return 1 : return 2;
    }
  14. A.
    returns 1
    B.
    returns 2
    C.
    varies
    D.
    Compile time error

  15. The output of the code below is

    void main()
    {
    int k = 8;
    int m = 7;
    k < m ? k++ : m = k;
    printf("%d", k);
    }
  16. A.
    7
    B.
    8
    C.
    Compile time error
    D.
    Run time error

  17. The output of the code below is

    void main()
    {
    int k = 8;
    int m = 7;
    k < m ? k = k + 1 : m = m + 1;
    printf("%d", k);
    }
  18. A.
    Compile time error
    B.
    9
    C.
    8
    D.
    Run time error

  19. For initialization a = 2, c = 1 the value of a and c after this code will be c = (c) ? a = 0 : 2;
  20. A.
    a = 0, c = 0;
    B.
    a = 2, c = 2;
    C.
    a = 2, c = 2;
    D.
    a = 1, c = 2;