Skip to content

Instantly share code, notes, and snippets.

@calvinfroedge
Created February 20, 2012 02:53
Show Gist options
  • Save calvinfroedge/1867451 to your computer and use it in GitHub Desktop.
Save calvinfroedge/1867451 to your computer and use it in GitHub Desktop.
Bitwise = mind blown
#include <stdio.h>
int printSomething()
{
printf("%s", "Something");
return 1;
}
int main()
{
int x = 3, y = 2;
int a = (x > y & y > 5 & printSomething()); //"Something" is printed
int b = (x > y && y > 5 && printSomething()); //"Something" is not printed. && operator short circuits and after y > 5 evaluates to false conditions stop being evaluated.
printf("Example 1: %d \n \n", a);
printf("Example 2: %d \n \n", b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment