Home / C Programming / Operators and Expressions :: Discussion

Discussion :: Operators and Expressions

  1. Determine output:

    void main()

    {

    int i=0, j=1, k=2, m;

    m = i++ || j++ || k++;

    printf("%d %d %d %d", m, i, j, k);

    }

  2. A.

     1 1 2 3

    B.

     1 1 2 2

    C.

     0 1 2 2

    D.

     0 1 2 3

    E.

     None of these

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    In an expression involving || operator, evaluation takes place from left to right and will be stopped if one of its components evaluates to true(a non zero value).

    So in the given expression m = i++ || j++ || k++.
    It will be stop at j and assign the current value of j in m.
    therefore m = 1 , i = 1, j = 2 and k = 2 (since k++ will not encounter. so its value remain 2)


Be The First To Comment