printf("%i\n",2&2==2);
This should print out a 1 but I get a 0, why is this?
int ans=2&2;
printf("%i\n",ans==2);
This prints a 1, how come the first way does not work? This is the case with if statements as well
printf("%i\n",2&2==2);
This should print out a 1 but I get a 0, why is this?
int ans=2&2;
printf("%i\n",ans==2);
This prints a 1, how come the first way does not work? This is the case with if statements as well
The order of operations is different than you think it is. A correct way to write it in a single line would be:
printf("%i\n", (2 & 2) == 2); // Prints 1