Home / C Programming / Control Structures :: Discussion

Discussion :: Control Structures

  1. What will be the output of the given program?

    #include<stdio.h>

    void main()

    {

    int value1, value2=100, num=100;

    if(value1=value2%5) num=5;

    printf("%d %d %d", num, value1, value2);

    }

  2. A.

     100 100 100

    B.

     5 0 20

    C.

     5 0 100

    D.

     100 0 100

    E.

     100 5 100

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    Expression value2%5 is equal to 0 and this value assigned to value1.
    Therefore

    if

    condition reduces to

    if(0)

    so it fails.
    Therefore body of

    if

    will not be executed i.e

    num = 5

    will not be assigned.
    So at printf num = 100 , value1 = 0 and value2 = 100.


Be The First To Comment