Evaluation of Logical Expressions

Table of contents:

In C and C++, evaluation of a logical expression stops as soon as the logical value of the entire expression is determined. This shortcut mechanism may leave some operands unevaluated. The value of an expression of the form

expr1 && expr2 && ... && exprn

is true if and only if all of the operands are true. If one or more of the operands is false, the value of the expression is false. Evaluation of the expression proceeds sequentially, from left to right, and is guaranteed to stop (and return the value false) if it encounters an operand that has the value false.

Similarly, an expression of the form

expr1 || expr2 || ... || exprn

is false if and only if all of the operands are false. Evaluation of the expression proceeds sequentially, from left to right, and is guaranteed to stop (and return the value true) if it encounters an operand that has the value true.

Programmers often exploit this system with statements like:

if( x != 0 && y/x < z) {
 // do something ...
 }
 else {
 // do something else ...
 }

If x were equal to 0, evaluating the second expression would produce a run-time error. Fortunately, that cannot happen.

Logical expressions often make use of both && and ||. It is important to remember that && has higher precedence than ||. In other words, x || y && z means x || (y && z), not (x || y) && z.


Enumerations

Part I: Introduction to C++ and Qt 4

C++ Introduction

Classes

Introduction to Qt

Lists

Functions

Inheritance and Polymorphism

Part II: Higher-Level Programming

Libraries

Introduction to Design Patterns

QObject

Generics and Containers

Qt GUI Widgets

Concurrency

Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments

Bibliography

MP3 Jukebox Assignments



An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net