tailieunhanh - Absolute C++ (4th Edition) part 6

Absolute C++ (4th Edition) part 6. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Boolean Expressions 5i because and have higher precedence than . In fact you could omit all the parentheses in the previous expression and it would have the same meaning although it would be harder to read. Although we do not advocate omitting all the parentheses it might be instructive to see how such an expression is interpreted using the precedence rules. Here is the expression without any parentheses x 1 2 x 1 -3 The precedences rules say first apply the unary - then apply the s then the and the and finally apply the which is exactly what the fully parenthesized version says to do. The previous description of how a Boolean expression is evaluated is basically correct but in C the computer actually takes an occasional shortcut when evaluating a Boolean expression. Notice that in many cases you need to evaluate only the first of two subexpressions in a Boolean expression. For example consider the following x 0 y 1 If x is negative then x 0 is false. As you can see in the tables in Display when one subexpression in an expression is false then the whole expression is false no matter whether the other expression is true or false. Thus if we know that the first expression is false there is no need to evaluate the second expression. A similar thing happens with expressions. If the first of two expressions joined with the operator is true then you know the entire expression is true no matter whether the second expression is true or false. The C language uses this fact to sometimes save itself the trouble of evaluating the second subexpression in a logical expression connected with an or . C first evaluates the leftmost of the two expressions joined short-circuit by an or . If that gives it enough information to determine the final value of the evaluation expression independent of the value of the second expression then C does not bother to evaluate the second expression. This method of evaluation is called shortcircuit evaluation. Some languages other than C use .

TỪ KHÓA LIÊN QUAN