The for loop for (i=0; i<10; ++i) printf("%d", i&1); prints:

2015

The for loop

for (i=0; i<10; ++i)
printf("%d", i&1);

prints:

  1. A.

    0101010101

  2. B.

    0111111111

  3. C.

    0000000000

  4. D.

    1111111111

Attempted by 536 students.

Show answer & explanation

Correct answer: A

The for loop iterates 10 times with i ranging from 0 to 9. Inside the loop, the expression i&1 performs a bitwise AND with 1. This operation checks the least significant bit of i: it returns 0 for even numbers and 1 for odd numbers. Since the loop starts at 0 (even) and increments by 1, the output alternates between 0 and 1. The resulting sequence is 0101010101.

Explore the full course: Isro