Dangling Else Example


   if (a == 1)
     if (b == 3)
       printf("\nsomething\n");
   else
     printf("\nanother something\n");

The indenting indicates that the else clause is intended to go with the first if (if (a == 1) ) but in actuality, it is attached to the second if since C attaches the else to the first if it can find going "backwards"

To "fix it" so that the intended logic is implemented you must use {}


   if (a == 1)
   {
     if (b == 3)
       printf("\nsomething\n");
   }
   else
     printf("\nanother something\n");