Last Updated : 13 Dec, 2018

Consider the given C program given below.

#include 
void swap (int *x, int *y)
{
    static int *temp;
    temp = x;
    x = y;
    y = temp;
}
void printab ()
{
    static int i, a = -3, b = -6;
    i = 0;
    while (i <= 4)
    {
        if (?) continue;                 // line 1
        a = a + i;
        b = b + i;
    }
    swap (&a, &b);
    printf(\"a =  %d, b = %d\\n\", a, b);
}
main()
{
    printab();
    printab();
}

What will be the condition in line 1 to generate the following output?
a = 6, b = 3
a = 15, b = 12

(A) (++i)%2 <= 1

(B) (++i)%2 <= 1

(C) (++i)/2 >= 1
(D) (++i)/2 <= 1

Answer: (D)

Explanation: Put one by one all the conditions
Only D satisfy.


Quiz of this Question


Share your thoughts in the comments