Q&A

Q1:Why use unnecessary parentheses when precedence will determine which operators are acted on first?
A1: Although it is true that the compiler will know the precedence and that a programmer can look up the precedence order, code that is easy to understand is easier to maintain.
Q2:If the relational operators always return 1 or 0, why are other values considered true?
A2: The relational operators return 1 or 0, but every expression returns a value, and those values can also be evaluated in an if statement. Here's an example:
if ( (x = a + b) == 35 )

This is a perfectly legal C++ statement. It evaluates to a value even if the sum of a and b is not equal to 35. Also note that x is assigned the value that is the sum of a and b in any case. ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.