1.5. Expressions
1
Lecturer: PhD. DO Thi Ngoc Diep
SCHOOL OF ELECTRICAL AND ELECTRONIC ENGINEERING
HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY
2
Expression
An expression that contains at least one operand and 0 or more operators
The operands can be: constant values, literals, variables, result of a function or
subexpressions
Operators have different precedence, but can be changed using brackets ()
Operators with the same precedence are performed from left to right
Examples:
47
i
x++
sin(x+2)
( 2 * log( ( 3 + 10 ) - ( 2 * 6 ) ) )
3
1.6. Operators
4
Operators in C
Assignment operator (=, +=, -=, *=, /=, …)
Arithmetic operators ( +, -, *, /, %)
Relational / comparison operators (==, != , >, <, >= , <=)
Bit operators (&, |, ^, ~, <<, >>)
Logical operators (&&, ||, !)
Other operators (sizeof(), pointer: *, address: &, etc.)
5
Assignment operator
=, +=, -=, *=, /=, %=
=
+=, -=, *=, /= , %=, &=, |=, ^=, >>=, <<=
a -= 5; means a = a - 5;
a /= b; means a = a / b;
a = b = c = 1 ;
int i=2, j, k ;
k=(j=i , i*2); /* j=i; k=i*2 ;
Result: i=2;j=2;k=4 */