Week 9 Operators 05122024 023311pm
Week 9 Operators 05122024 023311pm
FUNDAMENTALS
[CSC110]
Lecture No. 10
C++ Operators and
Conditional Structures
OPERATOR TYPES:
Type Operators Usage
Arithmetic ‘+’ ‘-’ ‘*’ ‘/’ ‘%’ a+b a-b a*b a/b a%b
Arithmetic ‘+=’ ‘-=’ ‘*=’ ‘/=’ ‘%=’ a+=b is the same as a=a+b
assignment a-=b a*=b a/=b a%=b
Increment and ‘++’ ‘- -’ a++ is the same as a=a+1
decrement a-- is the same as a=a-1
Relational ‘<’ ‘>’ ‘<=’ ‘>=’ ‘==’ ‘!=’
Logical ‘&&’ ‘||’
• 3%2 =1
• 5%2=1
• 6%3=0
• 8%5=3
• In c++
• Logical OR (||)
Prefix
++a;
--a;
Postfix
a++;
a--;
DEPARTMENT OF ELECTRICAL ENGINEERING
DEPARTMENT OF ELECTRICAL ENGINEERING
Precedence of Operators
OPERATORS TYPE
++ -- unary
* / % multiplicative
+ - additive
< > <= >= relational
== != equality
&& || logical
= *= /= %= += assignment
-=
• Languages: C++