0% found this document useful (0 votes)
10 views

Chapter 3 C

Uploaded by

mehdiajrhourh11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Chapter 3 C

Uploaded by

mehdiajrhourh11
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Operators and Expressions

 Arithmetic Operators
 Assignment Operators
 Relational Operators
 Logical Operators
Operators and Expressions
Arithmetic Operators
Unary plus and unary minus
Binary arithmetic operators
Division in C
✓ Integer division: C performs integer division if both operands are integer type.
Integer division always evaluates to an integer discarding the fractional part.

✓ Real division: C performs real division if any of the two operands are real type
(either float or double). Real division evaluates to a real value containing
integer as well as fractional part.
Remainder/Modulo division
Operator % evaluates remainder after performing division of two numbers.

Important note:
•Modulo division is only possible with integer
operands. It causes compilation error with
float types.
•Modulo operator returns sign of the first
operand.
Assignment
Assignment operator is used to assign value to a variable (memory
location). It evaluates expression on right side of = symbol and assigns
evaluated value to left side the variable.
Assignment
Assignment operator is used to assign value to a variable (memory
location). It evaluates expression on right side of = symbol and assigns
evaluated value to left side the variable.

The right side of assignment operator must be a constant, expression


or variable. Whereas left side must be a variable (valid memory
location).
Compound assignment

Compound assignment operator combines one of the arithmetic operators with


Assignment operator.
Compound assignment

Compound
Increment and Decrement operator in C

Increment and Decrement operator are used to increment or


decrement value by 1.

(compound assignment)
Prefix vs Postfix
Prefix first increment/decrements its value then returns the
result. Whereas postfix first returns the result then
increment/decrement the value.
Prefix vs Postfix
Precedence of operators

Precedence of an operator specifies its priority compared to


other operator.
Associativity of operators
Operator Description Precedence Associativity
() Parentheses
++ Postfix increment 1 Left to right
-- Postfix decrement
+ Unary plus operator
- Unary minus operator
2 Right to left
++ Prefix Increment
-- Prefix Decrement
* Multiply
/ Divide 3 Left to right
% Modulus
+ Binary addition
4 Left to right
- Binary subtraction
= Simple assignment Right to left
5
*= /= += -= Compound assignment

You might also like