Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help
next up previous
Next: Predefined functions Up: C++ Summary Previous: Built-in types

Expressions

Expressions are used to compute values by applying operators to variables, constants and literal values. The operators for the predefined types include:



integer ops +, -, *, /, % (modulus) e.g. (13+4)/5 is 3
real ops +, -, *, / e.g. (13.0+4.0)/5.0 is 3.4
relational ops ==, !=, >=, <=, >, < e.g. (6+2)<9 is true
logical ops && (and), || (or), ! (not) e.g. (6>8) || (3<4) is true
bit-shift ops >>, << e.g. 2<<10 is 2048

Precedence order:

1.
!, not (logical not)
2.
*, /, %
3.
+, -
4.
>>, <<
5.
<, <=, >, >=
6.
==, !=
7.
&&, and (logical and)
8.
||, or (logical or)

Increment and decrement operators (see section 8 on assignment statements):

 Operators can be defined for user types. See the use of << and >> in section 11, and the -- member function in the example class in section 18.


next up previous
Next: Predefined functions Up: C++ Summary Previous: Built-in types
© Cambridge University Engineering Dept
Information provided by Tim Love
2006-12-08