SlideShare a Scribd company logo
Operators & Expressions
Department of Computer Science
CLASS- BCA (Ist Semester)
SUBJECT: PROGRAMMING FUNDAMENTALS USING C
SUBMITTED BY : PARDEEP KAUR
Definition
“An operator is a symbol (+,-,*,/) that directs the
computer to perform certain mathematical or logical
manipulations and is usually used to manipulate data
and variables”
Ex: a+b
Operators in C
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
Arithmetic operators
Operator example Meaning
+ a + b Addition –unary
- a – b Subtraction- unary
* a * b Multiplication
/ a / b Division
% a % b Modulo division- remainder
Relational Operators
Operator Meaning
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal
to
== Equal to
!= Not equal to
Logical Operators
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Logical expression or a compound relational
expression-
An expression that combines two or more
relational expressions
Ex: if (a==b && b==c)
Truth Table
a b
Value of the expression
a && b a || b
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
Assignment operators
Syntax:
v op = exp;
Where v = variable,
op = shorthand assignment operator
exp = expression
Ex: x=x+3
x+=3
Shorthand Assignment operators
Simple assignment
operator
Shorthand operator
a = a+1 a + =1
a = a-1 a - =1
a = a* (m+n) a * = m+n
a = a / (m+n) a / = m+n
a = a %b a %=b
Increment & Decrement Operators
C supports 2 useful operators namely
1. Increment ++
2. Decrement – operators
The ++ operator adds a value 1 to the operand
The – operator subtracts 1 from the operand
++a or a++
--a or a--
Rules for ++ & -- operators
1. These require variables as their operands
2. When postfix either ++ or – is used with the
variable in a given expression, the
expression is evaluated first and then it is
incremented or decremented by one
3. When prefix either ++ or – is used with the
variable in a given expression, it is
incremented or decremented by one first
and then the expression is evaluated with
the new value
Examples for ++ & -- operators
Let the value of a =5 and b=++a then
a = b =6
Let the value of a = 5 and b=a++ then
a =5 but b=6
i.e.:
1. a prefix operator first adds 1 to the operand
and then the result is assigned to the variable
on the left
2. a postfix operator first assigns the value to
the variable on left and then increments the
operand.
Conditional operators
Syntax:
exp1 ? exp2 : exp3
Where exp1,exp2 and exp3 are expressions
Working of the ? Operator:
Exp1 is evaluated first, if it is nonzero(1/true) then the
expression2 is evaluated and this becomes the value of the
expression,
If exp1 is false(0/zero) exp3 is evaluated and its value becomes
the value of the expression
Ex: m=2;
n=3
r=(m>n) ? m : n;
Bitwise operators
These operators allow manipulation of data at the bit level
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Shift left
>> Shift right
Special operators
1. Comma operator ( ,)
2. sizeof operator – sizeof( )
3. Pointer operators – ( & and *)
4. Member selection operators – ( . and ->)
Arithmetic Expressions
Algebraic expression C expression
axb-c a*b-c
(m+n)(x+y) (m+n)*(x+y)
a*b/c
3x2
+2x+1 3*x*x+2*x+1
a/b
S=(a+b+c)/2
c
ab
b
a
2
c
b
a 

S=
Arithmetic Expressions
Algebraic expression C expression
area= area=sqrt(s*(s-a)*(s-b)*(s-c))
sin(b/sqrt(a*a+b*b))
tow1=sqrt((rowx-rowy)/2+tow*x*y*y)
tow1=sqrt(pow((rowx-rowy)/2,2)+tow*x*y*y)
y=(alpha+beta)/sin(theta*3.1416/180)+abs(x)
)
)(
)(
( c
s
b
s
a
s
s 


Sin








 2
2
b
a
b
2
1
2
xy
y
x



 





 

2
2
1
2
xy
y
x



 





 

x
y 





sin
Precedence of operators
BODMAS RULE-
Brackets of Division Multiplication Addition
Subtraction
Brackets will have the highest precedence and have to
be
evaluated first, then comes of , then comes
division, multiplication, addition and finally
subtraction.
C language uses some rules in evaluating the
expressions
and they r called as precedence rules or sometimes
also
referred to as hierarchy of operations, with some
operators
Rules for evaluation of expression
1. First parenthesized sub expression from left to right are
evaluated.
2. If parentheses are nested, the evaluation begins with the
innermost sub expression
3. The precedence rule is applied in determining the order of
application of operators in evaluating sub expressions
4. The associatively rule is applied when 2 or more operators of
the same precedence level appear in a sub expression.
5. Arithmetic expressions are evaluated from left to right using
the rules of precedence
6. When parentheses are used, the expressions within
parentheses assume highest priority
Hierarchy of operators
Operator Description Associativity
( ), [ ] Function call, array
element reference
Left to Right
+, -, ++, -
-,!,~,*,&
Unary plus, minus,
increment, decrement,
logical negation, 1’s
complement, pointer
reference, address
Right to Left
*, / , % Multiplication,
division, modulus
Left to Right
Example 1
Evaluate x1=(-b+ sqrt (b*b-4*a*c))/(2*a) @ a=1, b=-5,
c=6
=(-(-5)+sqrt((-5)(-5)-4*1*6))/(2*1)
=(5 + sqrt((-5)(-5)-4*1*6))/(2*1)
=(5 + sqrt(25 -4*1*6))/(2*1)
=(5 + sqrt(25 -4*6))/(2*1)
=(5 + sqrt(25 -24))/(2*1)
=(5 + sqrt(1))/(2*1)
=(5 + 1.0)/(2*1)
=(6.0)/(2*1)
=6.0/2 = 3.0
Example 2
Evaluate the expression when a=4
b=a- ++a
=a – 5
=5-5
=0
Basic operators and it's types in c languages

More Related Content

PPT
operator
PPTX
OPERATORS AND EXPRESSIONS IN PROGRAMMING IN C
PPTX
Operator.ppt
PDF
Coper in C
PPTX
3. C_OperatorsExpressions on c languyage.pptx
PDF
Unit ii chapter 1 operator and expressions in c
PPTX
Operators and Expressions
PPTX
Variables, Data Types, Operator & Expression in c in detail
operator
OPERATORS AND EXPRESSIONS IN PROGRAMMING IN C
Operator.ppt
Coper in C
3. C_OperatorsExpressions on c languyage.pptx
Unit ii chapter 1 operator and expressions in c
Operators and Expressions
Variables, Data Types, Operator & Expression in c in detail

Similar to Basic operators and it's types in c languages (20)

PPTX
Operators and expressions in c language
PPTX
Operators inc c language
PPTX
operators.pptx
PPTX
Operators in c by anupam
PDF
C Operators and Control Structures.pdf
PPTX
C Operators
PPTX
Opreator In "C"
PPTX
Operators-computer programming and utilzation
PPTX
c programming2.pptx
PPTX
C Operators and Control Structures.pptx
ODP
Operators
PDF
Operators in c
PDF
Module2.1_Programming_Branching_and_looping.pdf
PPTX
OPERATORS OF C++
PPTX
Operators and expressions in C++
PDF
introduction to c programming - Topic 3.pdf
PPTX
Operators and it's type
PPTX
Cse lecture-4.1-c operators and expression
PPT
C operators ppt
PPT
Operators in C
Operators and expressions in c language
Operators inc c language
operators.pptx
Operators in c by anupam
C Operators and Control Structures.pdf
C Operators
Opreator In "C"
Operators-computer programming and utilzation
c programming2.pptx
C Operators and Control Structures.pptx
Operators
Operators in c
Module2.1_Programming_Branching_and_looping.pdf
OPERATORS OF C++
Operators and expressions in C++
introduction to c programming - Topic 3.pdf
Operators and it's type
Cse lecture-4.1-c operators and expression
C operators ppt
Operators in C
Ad

More from BalaKrishnan466 (15)

PPT
Switch and control statement for c language
PPT
c-Looping-Statements-P-Suman statement for c
PPT
Switch and control looping statement for C
PPT
Switch and looping statement for c language
PPT
C language Looping and conditional statement
PDF
Control structure and Looping statements
PPT
Control structure and Looping statements
PPT
Control structure and Looping statements
PPT
Decision making in C(2020-2021) statements
PPT
C array and Initialisation and declaration
PPTX
Queues operation using data structure in c
PPT
Stack operation in data structure in c language
PPTX
Flow chart and algorithm working progress
PPT
Algorithms and Flowchart usages in C laguage
PPT
Data types and it's usage in c languages
Switch and control statement for c language
c-Looping-Statements-P-Suman statement for c
Switch and control looping statement for C
Switch and looping statement for c language
C language Looping and conditional statement
Control structure and Looping statements
Control structure and Looping statements
Control structure and Looping statements
Decision making in C(2020-2021) statements
C array and Initialisation and declaration
Queues operation using data structure in c
Stack operation in data structure in c language
Flow chart and algorithm working progress
Algorithms and Flowchart usages in C laguage
Data types and it's usage in c languages
Ad

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Institutional Correction lecture only . . .
PDF
Pre independence Education in Inndia.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
master seminar digital applications in india
PDF
01-Introduction-to-Information-Management.pdf
PDF
Business Ethics Teaching Materials for college
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Insiders guide to clinical Medicine.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Institutional Correction lecture only . . .
Pre independence Education in Inndia.pdf
Classroom Observation Tools for Teachers
Microbial diseases, their pathogenesis and prophylaxis
Microbial disease of the cardiovascular and lymphatic systems
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
TR - Agricultural Crops Production NC III.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Pharma ospi slides which help in ospi learning
Pharmacology of Heart Failure /Pharmacotherapy of CHF
master seminar digital applications in india
01-Introduction-to-Information-Management.pdf
Business Ethics Teaching Materials for college
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

Basic operators and it's types in c languages

  • 1. Operators & Expressions Department of Computer Science CLASS- BCA (Ist Semester) SUBJECT: PROGRAMMING FUNDAMENTALS USING C SUBMITTED BY : PARDEEP KAUR
  • 2. Definition “An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and variables” Ex: a+b
  • 3. Operators in C 1. Arithmetic operators 2. Relational operators 3. Logical operators 4. Assignment operators 5. Increment and decrement operators 6. Conditional operators 7. Bitwise operators 8. Special operators
  • 4. Arithmetic operators Operator example Meaning + a + b Addition –unary - a – b Subtraction- unary * a * b Multiplication / a / b Division % a % b Modulo division- remainder
  • 5. Relational Operators Operator Meaning < Is less than <= Is less than or equal to > Is greater than >= Is greater than or equal to == Equal to != Not equal to
  • 6. Logical Operators Operator Meaning && Logical AND || Logical OR ! Logical NOT Logical expression or a compound relational expression- An expression that combines two or more relational expressions Ex: if (a==b && b==c)
  • 7. Truth Table a b Value of the expression a && b a || b 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1
  • 8. Assignment operators Syntax: v op = exp; Where v = variable, op = shorthand assignment operator exp = expression Ex: x=x+3 x+=3
  • 9. Shorthand Assignment operators Simple assignment operator Shorthand operator a = a+1 a + =1 a = a-1 a - =1 a = a* (m+n) a * = m+n a = a / (m+n) a / = m+n a = a %b a %=b
  • 10. Increment & Decrement Operators C supports 2 useful operators namely 1. Increment ++ 2. Decrement – operators The ++ operator adds a value 1 to the operand The – operator subtracts 1 from the operand ++a or a++ --a or a--
  • 11. Rules for ++ & -- operators 1. These require variables as their operands 2. When postfix either ++ or – is used with the variable in a given expression, the expression is evaluated first and then it is incremented or decremented by one 3. When prefix either ++ or – is used with the variable in a given expression, it is incremented or decremented by one first and then the expression is evaluated with the new value
  • 12. Examples for ++ & -- operators Let the value of a =5 and b=++a then a = b =6 Let the value of a = 5 and b=a++ then a =5 but b=6 i.e.: 1. a prefix operator first adds 1 to the operand and then the result is assigned to the variable on the left 2. a postfix operator first assigns the value to the variable on left and then increments the operand.
  • 13. Conditional operators Syntax: exp1 ? exp2 : exp3 Where exp1,exp2 and exp3 are expressions Working of the ? Operator: Exp1 is evaluated first, if it is nonzero(1/true) then the expression2 is evaluated and this becomes the value of the expression, If exp1 is false(0/zero) exp3 is evaluated and its value becomes the value of the expression Ex: m=2; n=3 r=(m>n) ? m : n;
  • 14. Bitwise operators These operators allow manipulation of data at the bit level Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR << Shift left >> Shift right
  • 15. Special operators 1. Comma operator ( ,) 2. sizeof operator – sizeof( ) 3. Pointer operators – ( & and *) 4. Member selection operators – ( . and ->)
  • 16. Arithmetic Expressions Algebraic expression C expression axb-c a*b-c (m+n)(x+y) (m+n)*(x+y) a*b/c 3x2 +2x+1 3*x*x+2*x+1 a/b S=(a+b+c)/2 c ab b a 2 c b a   S=
  • 17. Arithmetic Expressions Algebraic expression C expression area= area=sqrt(s*(s-a)*(s-b)*(s-c)) sin(b/sqrt(a*a+b*b)) tow1=sqrt((rowx-rowy)/2+tow*x*y*y) tow1=sqrt(pow((rowx-rowy)/2,2)+tow*x*y*y) y=(alpha+beta)/sin(theta*3.1416/180)+abs(x) ) )( )( ( c s b s a s s    Sin          2 2 b a b 2 1 2 xy y x              2 2 1 2 xy y x              x y       sin
  • 18. Precedence of operators BODMAS RULE- Brackets of Division Multiplication Addition Subtraction Brackets will have the highest precedence and have to be evaluated first, then comes of , then comes division, multiplication, addition and finally subtraction. C language uses some rules in evaluating the expressions and they r called as precedence rules or sometimes also referred to as hierarchy of operations, with some operators
  • 19. Rules for evaluation of expression 1. First parenthesized sub expression from left to right are evaluated. 2. If parentheses are nested, the evaluation begins with the innermost sub expression 3. The precedence rule is applied in determining the order of application of operators in evaluating sub expressions 4. The associatively rule is applied when 2 or more operators of the same precedence level appear in a sub expression. 5. Arithmetic expressions are evaluated from left to right using the rules of precedence 6. When parentheses are used, the expressions within parentheses assume highest priority
  • 20. Hierarchy of operators Operator Description Associativity ( ), [ ] Function call, array element reference Left to Right +, -, ++, - -,!,~,*,& Unary plus, minus, increment, decrement, logical negation, 1’s complement, pointer reference, address Right to Left *, / , % Multiplication, division, modulus Left to Right
  • 21. Example 1 Evaluate x1=(-b+ sqrt (b*b-4*a*c))/(2*a) @ a=1, b=-5, c=6 =(-(-5)+sqrt((-5)(-5)-4*1*6))/(2*1) =(5 + sqrt((-5)(-5)-4*1*6))/(2*1) =(5 + sqrt(25 -4*1*6))/(2*1) =(5 + sqrt(25 -4*6))/(2*1) =(5 + sqrt(25 -24))/(2*1) =(5 + sqrt(1))/(2*1) =(5 + 1.0)/(2*1) =(6.0)/(2*1) =6.0/2 = 3.0
  • 22. Example 2 Evaluate the expression when a=4 b=a- ++a =a – 5 =5-5 =0