/* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include /* * bool.c -- demonstrates boolean operations and concepts in C */ typedef enum { FALSE, TRUE } bool; int main (int argc, char *argv[]) { int x = 0; int y = 1; bool is_equal; // is_equal will be given a value of 1 if x is equal to y, and 0 otherwise is_equal = (x == y); printf("is_equal: %d (x=%d, y=%d)\n", is_equal, x, y); // the same as above, just trying a different value for x x = 1; is_equal = (x == y); printf("is_equal: %d (x=%d, y=%d)\n", is_equal, x, y); // logical equality (==) and assignment (=) operators should be differentiated y = 0; is_equal = (x = y); printf("is_equal: %d (x=%d, y=%d)\n", is_equal, x, y); // logical equality (==) and assignment (=) operators should be differentiated y = 10; is_equal = (x = y); printf("is_equal: %d (x=%d, y=%d)\n", is_equal, x, y); /* is_equal is "typedef"ed to be a boolean, but there is nothing that prevents us from * assigning any integer to this "boolean" type variable. */ is_equal = 100; printf("is_equal: %d\n", is_equal); return 0; }