9 votes 9 votes The for loop for (i=0; i<10; ++i) printf("%d", i&1); prints 0101010101 0111111111 0000000000 1111111111 Programming in C isro2015 programming-in-c loop + – go_editor asked Jun 21, 2016 • edited Dec 9, 2022 by Lakshman Bhaiya go_editor 6.2k views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply pC commented Jul 2, 2016 reply Follow Share what the answer would be if it were printf("%d", i && 1); Could someone tell why it is happpening so ? 0 votes 0 votes Arjun commented Jul 2, 2016 reply Follow Share Every operator in C/C++ has a corresponding meaning and result comes from that. "&&" is a logical and operator and all logical operators return either 0 or 1. 2 votes 2 votes Please log in or register to add a comment.
1 votes 1 votes i&1 is basically checking whether i is even or odd.If it's even it'll return 1 else 0. Based on this I think output should be A. arpanmukherjee answered Jul 3, 2016 arpanmukherjee comment Share Follow See all 0 reply Please log in or register to add a comment.