To understand about Operator.
To learn about how many types of Operator.
To learn about Arithmetic Operator in C.
To use of Bitwise Operator in C.
To use of Relational Operator in C.
To learn about Logical Operator in C.
To learn about Assignment Operator in C.
To learn about Ternary Operator in C.
To learn about Unary & Binary Operator.
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
Β
C Operators
1. Paper: Introduction Programming Language using C
Paper ID: 20105
Paper Code: BCA 105
DR. VARUN TIWARI
(ASSOCIATE PROFESSOR)
(DEPARTMENT OF COMPUTER SCIENCE)
BOSCO TECHNICAL TRAINING SOCIETY,
DON BOSCO TECHNICAL SCHOOL, OKHLA ROAD , NEW DELHI
3. Objectives
In this unit you will learn:
1. To understand about Operator.
2. To learn about how many types of Operator.
3. To use of Bitwise Operator in C.
4. To use of Relational Operator in C.
5. To learn about Logical Operator in C.
6. To learn about Assignment Operator in C.
7. To learn about Ternary Operator in C.
8. To learn about Arithmetic Operator in C.
4. Operator: An operator is a symbol that is used to perform mathematical and logical
operation etc. in C language. Its tells to compiler to perform a specific calculation.
1. Arithmetic Operator
2. Relational Operator
3. Logical Operator
4. Bitwise Operator
5. Assignment Operator
6. Ternary Operator or Conditional Operator
7. Increment / Decrement Operator
8. Unary Operator and Binary Operator
5. 1. Arithmetic Operator: It is perform arithmetic operation in C.
Example -: In this program, user input two values from keyboard and perform arithmetic
operations such as addition, subtraction, multiplication, division, modulus and output is
displayed for each operation.
Operator Description
+ For Addition
- For Subtraction
* For Multiplication
/ For Division
% For Percentage (Modulus)
6.
7.
8. 2. Relational Operator: it is used to perform relation between two variables or it compare
the values of two variables in C.
Operator Description
> a>b (Compare a is greater than b) its return true/false
< a<b (Compare a is less than b) its return true/false
>= a>=b (Compare a is greater than equal to b) return true/false
<= a<=b (Compare a is less than equal to b) return true/false
== a==b (compare a is equal to b)
!= a!=b (compare a is not equal to b)
9.
10.
11. 3. Logical Operator: it is used to perform logical operation on the given expression.
Operator Description
&& Logical AND
|| Logical OR
! Logical NOT
12.
13. 4. Bitwise Operator: it is used to perform decimal value to covert binary value which are the
form of bits and bitwise operator works in these bits. Its perform bits operation.
Truth table of Bitwise Operator:
a b a&b (AND) a|b (OR) a^b (XOR)
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Operator Description
& Bitwise AND
| Bitwise OR
~ Bitwise NOT or Complement
^ Bitwise XOR
<< Bitwise Left Shift
>> Bitwise Right Shift
14.
15.
16. 5. Assignment Operator: it is used to assign a value of variable.
Operator Description
= a=10; (assign a value of variable)
C=a+b; (passing multiple variable value to a new variable)
17. 6. Ternary or Conditional Operator: it return one value. If the condition is true return first
otherwise it return second value. This operator is also called ternary operator.
Syn. (condition/expression? True : False)
Example: p=(i<10?11:12);
18.
19. 7. Increment / Decrement Operator: Increment operator increase a value of variable by
one and decrement operator is used to decrease a value of variable by one. This is two
types first is prefix and second is postfix.
Syn. ++variable name; (prefix) , variablename++ (postfix) (increment)
-- variable name (prefix) , variablename - - (postfix) (decrement)
example: ++p; (value of p increment before assigning it to the variable p) , p++ (value of
p increment after assigning it to the variable p) ;
-- p ; (value of p decrement before assigning it to the variable p) , p-- (value
of p decrement after assigning it to the variable p) ;
20.
21.
22.
23.
24.
25.
26. 8. Unary Operator and Binary Operator: Unary operators that operates or works with single
operand are called unary operator. (ex: ++,--,~,size of)
Binary operator that operates or works between the two variable are called binary
operator. (+,-,/,%,*)