+ 1

What is the output of this code?

for(int i=0; i<10; i++){ if(i&1){ cout<<i; }}

31st Aug 2018, 10:11 PM
M.Saariya Faiz
M.Saariya Faiz - avatar
2 Answers
+ 2
It will print all odd numbers in the range 0-10 in a row => 13579. i & 1 is a bitwise operation. It will check if i's last bit is 1, which is only true for odd numbers.
1st Sep 2018, 6:42 AM
Anna
Anna - avatar
+ 1
Just put it in the code playground and run to get the output, unless you want an explanation of how the code works
31st Aug 2018, 10:28 PM
J.G.
J.G. - avatar