What is the “hanging else” problem? (Is that the right name?)
Following a C++ coding standard (forgot which one) I always
use brackets (block) with control structures. So I don’t
normally have this problem (to which “if” does the last(?)
else belong), but for understanding possible problems in
foreign code it would be nice with a firm understanding of
this problem. I remember reading about it in a book about
Pascal many years ago, but I can’t find that book.
Which
ifdoes theelsebelong to?(Obviously you should ignore the indentation.)
That’s the “hanging else problem”.
C/C++ gets rid of the ambiguity by having a rule that says you can’t have an-
if-without-an-elseas theif-body of an-if-with-an-else.