I'm trying to understand what the below code is actually doing? I thought (i & 1) would display odd numbers and (i & 2) would display even numbers. But (i & 2) gives me another odd answer. What does this actually do?
Output for the below code is:
(i & 1) = 1,3,5,7,9
(i & 2) = 2,3,6,7
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
int main()
{
for (int i = 0; i < 10 ; i++)
{
if (i & 1)
{
cout << i << endl;
}
}
}