Solution for Exercise 8-9

ex0809

#include <stdio.h>

int main()
{
    int a,b;

    a = 5;
    b = -3;

    if(a==b);
        printf("%d equals %d\n",a,b);
    return(0);
}

Output

5 equals -3

Notes

* Smart compilers not only warn about this error, they even offer a suggestion. Here is what the clang compiler says:

10:10: warning: if statement has empty body
10:10: note: put the semicolon on a separate line to silence this warning

* The semicolon at the end of Line 10 is most likely a mistake, given the indentation of Line 11. The compiler doesn't catch this type of booboo; everything looks hunky and dorry.

* These types of errors can be insidious, not only because the compiler doesn't see them, but because they're difficult to catch.