Gotcha (programming)

In programming, a gotcha is a valid construct in a system, program or programming language that works as documented but is counter-intuitive and almost invites mistakes because it is both easy to invoke and unexpected or unreasonable in its outcome.

Example
The classic gotcha in C/C++ is the construct It is syntactically valid: it puts the value of  into   and then executes   if   is non-zero. Sometimes this is even intended. However most commonly it is a typo: the programmer probably meant which executes  if   and   are equal. Modern compilers will usually generate a warning when encountering the former construct (conditional branch on assignment, not comparison), depending on compiler options (e.g., the  option for gcc). To avoid this gotcha, there is a recommendation to keep the constants in the left side of the comparison, e.g.  rather than. This way, using  instead of   will cause a compiler error (see Yoda conditions). Many kinds of gotchas are not detected by compilers, however.