#include #include #include /** * example00 - A first example of the problems of not knowing order * of operations. */ int main (int argc, char *argv[]) { if (argc != 2) { printf ("Usage: example00 #\n"); return EX_USAGE; } int x = atoi (argv[1]); printf ("Bad approach.\n"); if (0 <= x <= 5) // 0 <= 6 true, value 1; 1 <= 5 // 0 <= -5 false, value 0 printf ("%d is in the range [0..5].\n", x); else printf ("%d is NOT in the range [0..5]\n", x); printf ("Good approach.\n"); if (0 <= x && x <= 5) // <= has higher precedence than && printf ("%d is in the range [0..5].\n", x); else printf ("%d is NOT in the range [0..5]\n", x); return EX_OK; } // main