Programming C++ Secations three
Programming C++ Secations three
Parentheses are used in C++ expressions in the same manner as in algebraic expressions.
we write a * ( b + c ).
There is no arithmetic operator for exponentiation in C++,
so x2 is represented as x * x.
34
Precedence of arithmetic operations
For example,
2 + 3 * 5 and (2 + 3) * 5
36
Precedence of arithmetic operations
? = 1 + 2 * (3 + 4)
37
Data Type of an Arithmetic Expression
Data type of an expression depends on the type of its operands
Data type conversion is done by the compiler
38
Data Type of an Arithmetic Expression
Example
int * int; result int
39
Increment and Decrement Operators
Examples :
++K , K++ k= K+1
--K , K-- K= K-1
43
Increment and Decrement Operators
x = 5;
Cout << ++x;
x = 5;
44
Cout << x++;
special assignment statements
C++ has special assignment statements called compound
assignments
+= , -= , *= , /= , %=
Example:
X +=5 ; means x = x + 5;
x *=y; means x = x * y;
x /=y; means x = x / y;
45