You are on page 1of 11

Operators

•Operators are used to perform operations on


variables and values.
•The value is called an operand, while the
operation (to be performed between the two
operands) is defined by an operator:
C++ divides the operators into the
following groups:

•Arithmetic operators
•Assignment operators
•Comparison operators
•Logical operators
•Bitwise operators
Arithmetic Operators
• Arithmetic operators are used to perform common
mathematical operations.
C++ Assignment Operators

• Assignment operators are used to assign values to


variables.

• In the example below, we use the assignment operator


(=) to assign the value 10 to a variable called x:

• int x = 10;
A list of all assignment operators:
C++ Comparison Operators
• Comparison operators are used to compare two values:
C++ Logical Operators
• Logical operators are used to determine the logic between variables
or values:
Exercise
Use the following value of x = 10, y=5
1.x+y =_____ 7.y-- =_____
2.x-y =_____ 8.x+=4 =_____
3.x*y =_____ 9.y*=5 =_____
4.x/y =_____ 10.y/=5 =_____
5.x%y =_____
6.x++ =_____
Answer the following:
Write only TRUE or FALSE.
Use the given value: x=5, y=8, z=12, m=-5, b=6, c=7
1. x!=y 7. b>x && y>m
2. x==m 8. c<b ||z<y
3. y<m 9. !(y<z&&m<b)
4. m<y 10.!(b>x||z>c)
5. x<=m
6. y>=5

You might also like