Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • Thank you, all the answers here are good, but your last block of code really helped me visualize what was going on. Commented Oct 14, 2014 at 17:48
  • 10
    I'll second @GingerPlusPlus comment. Side effects in a condition are generally not a good idea (although there are some consecrated idioms that use them); conditional side effects are horrible. And using ! to compare with zero, instead of being explicit. More obfuscation. Commented Oct 14, 2014 at 18:35
  • 2
    With rare exceptions (e.g. for parallel structure with inequality comparisons nearby) IMHO one should always write comparisons with zero using !var or bare var, especially when var is a pointer. The rationale is basically the same as why one should never write an explicit == true or == false. Commented Oct 14, 2014 at 18:46
  • 2
    @alex.forencich If you mean that raw pointers should be avoided when possible, sure, but pointers past the end of arrays are quite common and useful; random-access iterators are often simply thin wrappers around raw pointers, and in such a case a container's end() iterator is effectively the same as such a pointer. Commented Oct 15, 2014 at 2:06
  • 2
    The point of an example like this has nothing to do with being good code. It is a great debugging and logic exercise. Commented Oct 15, 2014 at 17:32