August 2012
Intermediate to advanced
976 pages
30h 17m
English
The fact that we can use assignment in a condition can have surprising effects:
if (i = j)
The condition in this if assigns the value of j to i and then tests the result of the assignment. If j is nonzero, the condition will be true. The author of this code almost surely intended to test whether i and j have the same value:
if (i == j)
Bugs of this sort are notoriously difficult to find. Some, but not all, compilers are kind enough to warn about code such as this example.
Read now
Unlock full access