WELCOME TO SOWMYA TUTORIALS
CLASS: BCA 1st SEMESTER | NEP|
INTRODUCTION TO C PROGRAMMING| L5
CHAPTER 2: OPERATORS AND EXPRESSIONS
Operators
An operator is a Symbol that performs an operation.
An operator acts some variables are called operands to get the
desired result.
Ex : a+b; Where a, b are operands and + is the operator.
Types of Operator
1) Arithmetic Operators.
2) Relational Operators.
3) Logical Operators.
4) Assignment Operators.
5). Unary Operators.
6) Conditional Operators.
7) Special Operators.
8) Bitwise Operators.
9) Shift Operators.
Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition, subtraction and
multiplication on numerical values (constants and variables).
OPERATOR DESCRIPTION
+ ADDITION
- SUBTRACTION
* MULTIPLICATION
/ DIVISION
% MODULAS
Relational Operators.
A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns
value 0. Operands may be variables, constants or expressions.
Relational operators are used in decision making and loops.
Operator Meaning Example Return value
< is less than 2< 9 1
<= is less than or equal to 2<=2 1
> is greater than 2 > 9 0
>= is greater than or equal to 3>=2 1
== is equal to 2==3 0
!= is not equal to 2!=2 0
Logical Operators
These operators are used to combine the results of two or more conditions.
An expression containing logical operator returns either 0 or 1 depending upon whether
expression results true or false.
Logical operators are commonly used in decision making in C programming.
Operator Meaning Example Return value
&& Logical AND (9>2)&&(17>2) 1
|| Logical OR (9>2) || (17 = = 7) 1
! Logical NOT 29!=29 0
Logical AND : If any one condition false the complete condition becomes false.
Truth Table
Op1 Op2 Op1 && Op2
false(0) false(0) false(0)
false(0) true(1) false(0)
true(1) false(0) false(0)
true(1) true(1) true(1)
Logical OR : If any one condition true the complete condition becomes true.
Truth Table
Op1 Op2 Op1 || Op2
false(0) false(0) false(0)
false(0) true(0) true (1)
true(1) false(0) true (1)
true(1) true(1) true(1)
Logical Not : This operator reverses the value of the expression it operates on i.e, it
makes a true expression false and false expression true.
truth table
Op1 Op1 !
false(0) true (1)
true(1) false (0)
Assignment Operators
Assignment operators are used to assign a value (or) an expression (or) a
value of a variable to another variable.
Syntax : variable name=expression (or) value (or) variable
Ex : x=10;
y=a+b;
z=p;
Compound assignment operator
‘C’ provides compound assignment operators to assign a value to variable in order
to assign a new value to a variable after performing a specified operation.
Operator Example Meaning
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y X=x%y
THANK YOU
If you like my videos please do subscribe
and click on the bell icon for the
notification of the new videos.