SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Operators & Expressions
Operators
• C supports rich set of operators.
• An operator is a symbol that tells the computer to
perform certain mathematical or logical manipulations.
• Operators are used in programs to manipulate data and
variables.
Types of ‘C’ operators
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
1. Arithmetic operator
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo division
2. Relational operator
C supports six Relational Operators
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal to
== Is equal to
!= Is not equal to
3.Logical operators
• Logical Operators
– &&, || and ! are the three logical operators.
– expr1 && expr2 has a value 1 if expr1 and expr2 both are
nonzero.
– expr1 || expr2 has a value 1 if expr1 and expr2 both are
nonzero.
– !expr1 has a value 1 if expr1 is zero else 0.
– Example
– if ( marks >= 40 && attendance >= 75 ) grade = ‘P’
– If ( marks < 40 || attendance < 75 ) grade = ‘N’
4. Assignment operators
• Assignment operators are used to assign the result of an
expression to a variable.
• C has a set of ‘shorthand’ assignment operator (op=):
v op =exp;
Exam - a += 3 ;
a = a + 3 ;
Both are same.
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
5. Increment and decrement operators.
• Increment Operator ++
a=10;
a++ or a+1=11;
• Decrement Operator --
b=5;
b-- or b-1=4;
• Similarly increment and decrement operator is used in
subscripted variables as:
a[ i++]=5;
is equivalent to
a[ i]=5;
i=i+1;
6. Conditional operator
• C supports a ternary operator i.e. conditional operator.
• The conditional operator is defined as
“ ? : ”
• The conditional operator works in following format:
for example:
a=11;
b=20;
x=(a>b) ? a : b;
7. Bitwise operator
• C supports bitwise operators for manipulation of data at bit
level.
• Bitwise operators may not be applied to float or double.
• Bitwise operators are as follows:
& bitwise AND
| bitwise OR
^ bitwise exclusive OR
<< shift left
>> shift right
~ One’s Complements
8. Special operator
• C supports some special operators such as:
comma operator “,”
x=(a=5,b=6)
size of operator “sizeof()”
Address operator “&”
pointer operator “*”
member selection operator “. and -> ”
More about operators
• Unary operator
• Binary operator
• Ternary operator
Precedence of operators
• Precedence establishes the hierarchy of one set of operators
over another when an arithmetic expression has to be
evaluated.
• It refers to the order in which c evaluates operators.
• The evaluation of operators in an arithmetic
expression takes place from left to right for operators having
equal precedence .
Exam. k = 2 * 3/4 + 4/4 + 8–2 + 5/8 ;
O/P => 8
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 with highest
precedence and some with least.
The 2 distinct priority levels of arithmetic operators in c are-
Highest priority : * / %
Lowest priority : + -
Associativity of operators
• Associativity tells how an operator associates with its operands.
for eg:
1. The unary minus associates minus with the quantity to its right.
2. The assignment operator = associates from right to left.
• Hence the expression on the right is evaluated first and its value is
assigned to the variable on the left.
• Associativity also refers to the order in which c evaluates operators in an
expression having same precedence.
• Such type of operator can operate either left to right or vice versa.
• The operator () function call has highest precedence & the comma
operator has lowest precedence
• All unary , conditional & assignment operators associate RIGHT TO
LEFT .
• All other remaining operators associate LEFT TO RIGHT
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
Reference:
Presentation: Operators & Expressions
Published by: Godwin Robinson
URL: https://slideplayer.com/slide/9355540/

More Related Content

PPTX
PPT
Operator & Expression in c++
PPTX
Sparse matrix
PPT
Chapter 5 -Syntax Directed Translation - Copy.ppt
PDF
Chapter 5 - Operators in C++
PPT
PPTX
Operators in Python
PDF
sparse matrix in data structure
Operator & Expression in c++
Sparse matrix
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 - Operators in C++
Operators in Python
sparse matrix in data structure

What's hot (20)

PPTX
stack & queue
PPTX
Arithmetic Expression
PPTX
Stacks IN DATA STRUCTURES
PPT
Control structure C++
PPTX
Regular Expression to Finite Automata
PPTX
LL(1) parsing
PDF
Symbol table in compiler Design
PDF
List , tuples, dictionaries and regular expressions in python
PPT
Minimization of DFA
PPTX
Operator.ppt
PPTX
Pointers in c++
PPT
Infix prefix postfix
PDF
Bottom up parser
PPTX
Stack and Queue
PPTX
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
PPTX
Operators in C
PPT
Control structures in C++ Programming Language
PPTX
STACKS IN DATASTRUCTURE
PPTX
sorting and its types
PPTX
Alpha beta pruning in ai
stack & queue
Arithmetic Expression
Stacks IN DATA STRUCTURES
Control structure C++
Regular Expression to Finite Automata
LL(1) parsing
Symbol table in compiler Design
List , tuples, dictionaries and regular expressions in python
Minimization of DFA
Operator.ppt
Pointers in c++
Infix prefix postfix
Bottom up parser
Stack and Queue
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Operators in C
Control structures in C++ Programming Language
STACKS IN DATASTRUCTURE
sorting and its types
Alpha beta pruning in ai
Ad

Similar to Operators and Expressions (20)

PPTX
OPERATORS OF C++
PPTX
Operators in C Programming
PDF
Unit ii chapter 1 operator and expressions in c
PDF
SPL 6 | Operators in C
PDF
Module2.1_Programming_Branching_and_looping.pdf
PPTX
IOS Swift Language 3rd tutorial
PPTX
C Operators
PPTX
Operators and it's type
PDF
Types of Operators in C
PDF
Coper in C
PPTX
Basic c operators
ODP
Operators
PPTX
OPERATORS IN C.pptx
PPTX
OPERATORS IN C.pptx
PPTX
Operator in c programming
PPTX
Operators in C/C++
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 5
PPT
Operators and Expressions in C++
OPERATORS OF C++
Operators in C Programming
Unit ii chapter 1 operator and expressions in c
SPL 6 | Operators in C
Module2.1_Programming_Branching_and_looping.pdf
IOS Swift Language 3rd tutorial
C Operators
Operators and it's type
Types of Operators in C
Coper in C
Basic c operators
Operators
OPERATORS IN C.pptx
OPERATORS IN C.pptx
Operator in c programming
Operators in C/C++
Python Programming | JNTUK | UNIT 1 | Lecture 5
Operators and Expressions in C++
Ad

More from Munazza-Mah-Jabeen (20)

PPTX
Virtual Functions
PPTX
The Standard Template Library
PPTX
Object-Oriented Software
PPTX
Templates and Exceptions
PPTX
Dictionaries and Sets
PPTX
More About Strings
PPTX
Streams and Files
PPTX
Lists and Tuples
PPT
Files and Exceptions
PPT
PPTX
PPT
Repitition Structure
PPTX
Inheritance
PPTX
Operator Overloading
PPT
Memory Management
PPTX
Arrays and Strings
PPTX
Objects and Classes
PPTX
PPTX
Structures
PPTX
Loops and Decisions
Virtual Functions
The Standard Template Library
Object-Oriented Software
Templates and Exceptions
Dictionaries and Sets
More About Strings
Streams and Files
Lists and Tuples
Files and Exceptions
Repitition Structure
Inheritance
Operator Overloading
Memory Management
Arrays and Strings
Objects and Classes
Structures
Loops and Decisions

Recently uploaded (20)

PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Lesson notes of climatology university.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Trump Administration's workforce development strategy
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
1_English_Language_Set_2.pdf probationary
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
Cell Types and Its function , kingdom of life
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Introduction to Building Materials
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Classroom Observation Tools for Teachers
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
IGGE1 Understanding the Self1234567891011
Lesson notes of climatology university.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Trump Administration's workforce development strategy
UNIT III MENTAL HEALTH NURSING ASSESSMENT
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
1_English_Language_Set_2.pdf probationary
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Cell Types and Its function , kingdom of life
Complications of Minimal Access Surgery at WLH
Orientation - ARALprogram of Deped to the Parents.pptx
LDMMIA Reiki Yoga Finals Review Spring Summer
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Introduction to Building Materials
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Classroom Observation Tools for Teachers
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Final Presentation General Medicine 03-08-2024.pptx
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx

Operators and Expressions

  • 2. Operators • C supports rich set of operators. • An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations. • Operators are used in programs to manipulate data and variables.
  • 3. Types of ‘C’ operators 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. 1. Arithmetic operator + Addition - Subtraction * Multiplication / Division % Modulo division
  • 5. 2. Relational operator C supports six Relational Operators < Is less than <= Is less than or equal to > Is greater than >= Is greater than or equal to == Is equal to != Is not equal to
  • 6. 3.Logical operators • Logical Operators – &&, || and ! are the three logical operators. – expr1 && expr2 has a value 1 if expr1 and expr2 both are nonzero. – expr1 || expr2 has a value 1 if expr1 and expr2 both are nonzero. – !expr1 has a value 1 if expr1 is zero else 0. – Example – if ( marks >= 40 && attendance >= 75 ) grade = ‘P’ – If ( marks < 40 || attendance < 75 ) grade = ‘N’
  • 7. 4. Assignment operators • Assignment operators are used to assign the result of an expression to a variable. • C has a set of ‘shorthand’ assignment operator (op=): v op =exp; Exam - a += 3 ; a = a + 3 ; Both are same.
  • 8. 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
  • 9. 5. Increment and decrement operators. • Increment Operator ++ a=10; a++ or a+1=11; • Decrement Operator -- b=5; b-- or b-1=4; • Similarly increment and decrement operator is used in subscripted variables as: a[ i++]=5; is equivalent to a[ i]=5; i=i+1;
  • 10. 6. Conditional operator • C supports a ternary operator i.e. conditional operator. • The conditional operator is defined as “ ? : ” • The conditional operator works in following format: for example: a=11; b=20; x=(a>b) ? a : b;
  • 11. 7. Bitwise operator • C supports bitwise operators for manipulation of data at bit level. • Bitwise operators may not be applied to float or double. • Bitwise operators are as follows: & bitwise AND | bitwise OR ^ bitwise exclusive OR << shift left >> shift right ~ One’s Complements
  • 12. 8. Special operator • C supports some special operators such as: comma operator “,” x=(a=5,b=6) size of operator “sizeof()” Address operator “&” pointer operator “*” member selection operator “. and -> ”
  • 13. More about operators • Unary operator • Binary operator • Ternary operator
  • 14. Precedence of operators • Precedence establishes the hierarchy of one set of operators over another when an arithmetic expression has to be evaluated. • It refers to the order in which c evaluates operators. • The evaluation of operators in an arithmetic expression takes place from left to right for operators having equal precedence . Exam. k = 2 * 3/4 + 4/4 + 8–2 + 5/8 ; O/P => 8
  • 15. 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 with highest precedence and some with least. The 2 distinct priority levels of arithmetic operators in c are- Highest priority : * / % Lowest priority : + -
  • 16. Associativity of operators • Associativity tells how an operator associates with its operands. for eg: 1. The unary minus associates minus with the quantity to its right. 2. The assignment operator = associates from right to left. • Hence the expression on the right is evaluated first and its value is assigned to the variable on the left. • Associativity also refers to the order in which c evaluates operators in an expression having same precedence. • Such type of operator can operate either left to right or vice versa. • The operator () function call has highest precedence & the comma operator has lowest precedence • All unary , conditional & assignment operators associate RIGHT TO LEFT . • All other remaining operators associate LEFT TO RIGHT
  • 17. 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
  • 18. 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
  • 19. Reference: Presentation: Operators & Expressions Published by: Godwin Robinson URL: https://slideplayer.com/slide/9355540/