Page 265 - Computer_Science_F5
P. 265
Computer Science Operator precedence in C++
Table 4.12 illustrates the level of precedence of the operators in C++
Table 4.12: Operator precedence in C++
Operators
Priority
FOR ONLINE READING ONLY
Highest
Priority ( , )
++, -- (as postfix), new, (type),typeof, sizeof
++, -- (as prefix), +, - (unary), !, ~
*, /, %
+ (string concatenation)
+, -
<<, >>
<, >, <=, >=, is, as
= =, !=
&, ^, |
Expressions
In C++, an expression is a combination of variables, constants, operators, and
functions that are evaluated to produce a value. Expressions are the building blocks
of C++ programs, used to perform calculations, make decisions, and manipulate
data. Here are some key points about expressions:
Types of expressions
(a) Arithmetic expressions
These include basic arithmetic operations such as addition (+), subtraction (-),
multiplication (*), and division (/).
For, example: int result = a + b - c * d / e;
(i) Mathematical expressions in C++ programming
Like other languages, the C++ programming language provides rules through
which different data, including variables, constants and operators, can be combined.
Such an interconnection of data is known as expression. During programming, the
arithmetic expression should be translated into C++ expression so that a compiler
can understand what is programmed.
⎡ 2x 1 ⎤
For example, the expression 10 ⎢ − ⎥ can be translated into C++ expression as
10*( (2*x)/3 – 1/3). ⎢ ⎣ 3 3 ⎥ ⎦
256
for Advanced Secondary Schools
Computer Science Form 5.indd 256 23/07/2024 12:33

