CP DML Q45

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

  • Option : 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
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *