Professional Documents
Culture Documents
1T4- Programming in c
Learning Objectives
• Student will be able to understand operators in c
• Student will be able to use operators in program
• Student will be able to use different types of operators in programming construct
Operators
Operator is a special symbol that tells the
compiler to perform specific mathematical or
logical Operation.
Types of Operators
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Ternary or Conditional Operators
• sizeof operator
Arithmetic operator
Example (int A=8,
Operator B=3) Result
+ A+B 11
- A-B 5
* A*B 24
/ A/B 2
% A%4 0
Relational operator
Example (int A=8,
Operators B=3) Result
! !(B<=-A) True
Truth table of Logical Operator
• pre-increment ++a
• post-increment a++
• pre-decrement --a
• post-decrement a--
Assignment operator
Operator Example (int A=8, Result
B=3)
+= A+=B or A=A+B 11
-= A-=3 or A=A+3 5
*= A*=7 or A=A*7 56
/= A/=B or A=A/B 2
%= A%=5 or A=A%5 3
Value of b will be
=a=b
assigned to a
Ternary operator
• If any operator is used on three operands or
variable is known as Ternary Operator. It can
be represented with ? : . It is also called
as conditional operator
• For ex.
• Exp1?exp2:exp3
Sizeof Operator
• The sizeof operator is used to calculate the
size of data type or variables. This operator
returns the size of its variable in bytes.
• For example: sizeof(a), where a is interger, will
return 2.
Thank You