C Programming MCQ

1:

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

prints

A.

0101010101

B.

01111111111

C.

0000000000

D.

111111111

 

Answer : A

Explanation :

The binary representation of odd numbers will have a 1 as the least significant digit. So, an odd number ANDed with 1, produces a 1 . Even number end with 0. So. an even number ANDed with 1, produces a 0. This for loop generates even and odd numbers alternatively. So. it prints alternate 0's and 1's.

Write your comments here:


Report Error
 

Option: A

Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here.