Home / C Programming / Operators and Expressions :: Discussion

Discussion :: Operators and Expressions

  1. What will be the output of this program on an implementation where int occupies 2 bytes?

    #include <stdio.h>

    void main()

    {

    int i = 3;

    int j;

    j = sizeof(++i + ++i);

    printf("i=%d j=%d", i, j);

    }

  2. A.

     i=4 j=2

    B.

     i=3 j=2

    C.

     i=5 j=2

    D.

     the behavior is undefined

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    Evaluating ++i + ++i would produce undefined behavior, but the operand of sizeof is not evaluated, so i remains 3 throughout the program. The type of the expression (int) is reduced at compile time, and the size of this type (2) is assigned to j.


Be The First To Comment