SlideShare a Scribd company logo
Operators and
Expressions


 Name : Vishaljot Kaur Thind
 Section : N2
 Roll No : 115335




                                1
Contents
 Objective
 Introduction
 Arithmetic operations
 Arithmetic expressions
 Relational operators
 Logical operators
 Assignment operators
 Increment and decrement operators
 Conditional operators
 Type conversions in expressions

                                      2
Objectives
♥ To be able to construct and evaluate
  expressions.
♥ To master operator precedence and
  associativity
♥ To understand implicit type conversion and
  explicit type conversion.




                                               3
3.1 Introduction
 An operator is a symbol that tells the computer to
  perform certain manipulations.
 An expression is a sequence of operands and operators
  that reduces to a single value.
 C operators can be classified into a number of
  categories.
    ◦   Arithmetic operators
    ◦   Relational operators
    ◦   Logical operators
    ◦   Assignment operators
    ◦   Increment and decrement operators
    ◦   Conditional operators
    ◦   Bitwise operators
    ◦   Special operators

                                                      4
5


3.2          Arithmetic operators
   The arithmetic operators in C

      Operator                      meaning
         +        Addition or unary plus
         -        Subtraction or unary minus
         *        Multiplication
         /        Division
         %        modulo division
6


3.2         Arithmetic operators
   Note:,
    ◦ Integer division truncates remainder
    ◦ The % operator cannot be applied to a float or
      double.
    ◦ The precedence of arithmetic operators
       Unary + or -
      * / %
      + -
7


3.10           Arithmetic expressions
   An arithmetic expression is a combination of variables,
    constants, and operators.
   For example,
   a*b-c           a*b-c
   (m+n)(x+y)             (m+n)*(x+y)
   ax2+bx+c        a*x*x+b*x+c
8


3.3 Relational Operators
• The relational operators in C are :

      Operator                    Meaning
         <           less that
        <=           less than or equal to
         >           greater than
        >=           greater than or equal to
        ==           equal to
        !=           not equal to
Relational Operators
   A relational expression yields a value
    of 1 or 0.
    ◦5<6                  1
    ◦ -34 + 8 > 23 - 5        0
    ◦ if a=3, b=2, c =1; then a > b > c is ?


   the associativity of relational
    operators is
    left  right
                                               9
3.4 Logical operators
   C has the following three logical
    operators
    ◦ && meaning logical and
    ◦ || meaning logical or
    ◦ ! meaning logical not ( unary operator )
   Expressions connected by && or || are
    evaluated left to right, and evaluation
    stops as soon as the truth or
    falsehood of the result is known.
                                                 10
3.5 Assignment operators
   The use of shorthand assignment
    operators has three advantages:
    ◦ 1. What appears on the left-hand side
      need not be repeated and therefore it
      becomes easier to write.
    ◦ 2. The statement is more concise and
      easier to read.
    ◦ 3. The statement is more efficient.



                                              11
3.6 Increment and decrement
operators
 C provides two unusual operators for
  incrementing and decrementing
  variables.
 The increment operator ++ adds 1 to its
  operand, while the decrement operator --
  subtracts 1.
 The unusual aspect is that ++ and -- may
  be used either as prefix operators
  (before the variable, as in ++n), or postfix
  operators (after the variable: n++).
 In both cases, the effect is to increment
  n. But the expression ++n increments n
  before its value is used, while n++
  increments n after its value has been
  used.
                                             12
   The increment and decrement operators
    can be used in complex statements.
    Example:
                m=n++ -j +10;

   Consider the expression
                  m = - n++ ;
   The precedence of ++ and – operators
    are the same as those of unary + and -.
   The associatively of them is right to left.
   m = - n++; is equivalent to m = - (n++)
                                                  13
3.7 Conditional operator
 a ternary operator pair “? : ” is
  available in C to construct conditional
  expressions of the form
             expr1 ? expr2 : expr3
 the expression expr1 is evaluated first.
  If it is non-zero (true), then the
  expression expr2 is evaluated, and
  that is the value of the conditional
  expression. Otherwise expr3 is
  evaluated, and that is the value. Only
  one of expr2 and expr3 is evaluated.
                                         14
   z = (a > b) ? a : b;   /* z = max(a, b) */




                                             15
3.9 Special operators
 1. The Comma Operator
 The comma operator can be used to link the
  related expressions together. A comma-linked
  list of expressions is evaluated left to right
  and the value of right-most expression is the
  value of the combined expression. For
  example, the statement
 value = (x=10, y=5, x+y);
 first assigns the value 10 to x, then assigns 5
  to y, and finally assigns 15 to value. Since
  comma operator has the lowest precedence
  of all operators, the parentheses are
  necessary.
                                                16
3.14 Type conversions in
expressions
 1. Implicit Type Conversion
 C permits mixing of constants and
  variables of different types in an
  expression. C automatically converts any
  intermediate values to the proper type so
  that the expression can be evaluated
  without loosing any significance. This
  automatic conversion is known as
  implicit type conversion.
 The rule of type conversion: the lower
  type is automatically converted to the
  higher type.
                                          17
3.13 Some Computational
Problems
   When expressions include real values,
    then it is important to take necessary
    precautions to guard against certain
    computational errors. For example,
    consider the following statements:
    ◦ a = 1.0 / 3.0;
    ◦ b = a * 3.0;
 There is no guarantee that the value of b
  will equal 1.
 Another problem is division by zero.
 The third problem is to avoid overflow
  and underflow errors.
                                              18
3.15   Operator precedence
and Associativity
   Rules of Precedence and Associativity
    ◦ (1)Precedence rules decides the order in which
      different operators are applied.
    ◦ (2)Associativity rule decide the order in which
      multiple occurrences of the same level operator
      are applied.
   Table3.8 on page71 shows the summary of C
    Operators.
   for example,
   a = i +1== j || k and 3 != x

                                                        19
   THANKS
             20

More Related Content

What's hot

Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in JavaAbhilash Nair
 
Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
Function overloading
Function overloadingFunction overloading
Function overloading
Selvin Josy Bai Somu
 
What are variables and keywords in c++
What are variables and keywords in c++What are variables and keywords in c++
What are variables and keywords in c++
Abdul Hafeez
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
daxesh chauhan
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
Nitin Jawla
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
Kamal Acharya
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
Siddique Ibrahim
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
The Loops
The LoopsThe Loops
The Loops
Krishma Parekh
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
Badrul Alam
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
Shobi P P
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
Operators in java
Operators in javaOperators in java
Operators in java
Muthukumaran Subramanian
 

What's hot (20)

Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in Java
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
What are variables and keywords in c++
What are variables and keywords in c++What are variables and keywords in c++
What are variables and keywords in c++
 
Principles and advantages of oop ppt
Principles and advantages of oop pptPrinciples and advantages of oop ppt
Principles and advantages of oop ppt
 
Control structures in c++
Control structures in c++Control structures in c++
Control structures in c++
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming Expression and Operartor In C Programming
Expression and Operartor In C Programming
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Data types in C
Data types in CData types in C
Data types in C
 
The Loops
The LoopsThe Loops
The Loops
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Operators in java
Operators in javaOperators in java
Operators in java
 

Similar to Operators and expressions

Operator in C language
Operator in C languageOperator in C language
Operator in C language
KanhaiyaSharma52
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
Kathirvel Ayyaswamy
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsdishti7
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Deepak Singh
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
ranaashutosh531pvt
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
YuvarajuCherukuri
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
V.V.Vanniapermal College for Women
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
Asheesh kushwaha
 
Coper in C
Coper in CCoper in C
Coper in C
thirumalaikumar3
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
Jasleen Kaur (Chandigarh University)
 
operator (1).pptx
operator (1).pptxoperator (1).pptx
operator (1).pptx
laptophp39
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
Muhammad Hammad Waseem
 
Theory3
Theory3Theory3
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
divyalakshmi77
 

Similar to Operators and expressions (20)

Operator in C language
Operator in C languageOperator in C language
Operator in C language
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
 
Report on c
Report on cReport on c
Report on c
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
 
This slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptxThis slide contains information about Operators in C.pptx
This slide contains information about Operators in C.pptx
 
c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
 
Opeartor &amp; expression
Opeartor &amp; expressionOpeartor &amp; expression
Opeartor &amp; expression
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
Coper in C
Coper in CCoper in C
Coper in C
 
Operators
OperatorsOperators
Operators
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 
operator (1).pptx
operator (1).pptxoperator (1).pptx
operator (1).pptx
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
Theory3
Theory3Theory3
Theory3
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
 

Recently uploaded

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 

Operators and expressions

  • 1. Operators and Expressions  Name : Vishaljot Kaur Thind  Section : N2  Roll No : 115335 1
  • 2. Contents  Objective  Introduction  Arithmetic operations  Arithmetic expressions  Relational operators  Logical operators  Assignment operators  Increment and decrement operators  Conditional operators  Type conversions in expressions 2
  • 3. Objectives ♥ To be able to construct and evaluate expressions. ♥ To master operator precedence and associativity ♥ To understand implicit type conversion and explicit type conversion. 3
  • 4. 3.1 Introduction  An operator is a symbol that tells the computer to perform certain manipulations.  An expression is a sequence of operands and operators that reduces to a single value.  C operators can be classified into a number of categories. ◦ Arithmetic operators ◦ Relational operators ◦ Logical operators ◦ Assignment operators ◦ Increment and decrement operators ◦ Conditional operators ◦ Bitwise operators ◦ Special operators 4
  • 5. 5 3.2 Arithmetic operators  The arithmetic operators in C Operator meaning + Addition or unary plus - Subtraction or unary minus * Multiplication / Division % modulo division
  • 6. 6 3.2 Arithmetic operators  Note:, ◦ Integer division truncates remainder ◦ The % operator cannot be applied to a float or double. ◦ The precedence of arithmetic operators  Unary + or - * / % + -
  • 7. 7 3.10 Arithmetic expressions  An arithmetic expression is a combination of variables, constants, and operators.  For example,  a*b-c  a*b-c  (m+n)(x+y)  (m+n)*(x+y)  ax2+bx+c  a*x*x+b*x+c
  • 8. 8 3.3 Relational Operators • The relational operators in C are : Operator Meaning < less that <= less than or equal to > greater than >= greater than or equal to == equal to != not equal to
  • 9. Relational Operators  A relational expression yields a value of 1 or 0. ◦5<6 1 ◦ -34 + 8 > 23 - 5 0 ◦ if a=3, b=2, c =1; then a > b > c is ?  the associativity of relational operators is left  right 9
  • 10. 3.4 Logical operators  C has the following three logical operators ◦ && meaning logical and ◦ || meaning logical or ◦ ! meaning logical not ( unary operator )  Expressions connected by && or || are evaluated left to right, and evaluation stops as soon as the truth or falsehood of the result is known. 10
  • 11. 3.5 Assignment operators  The use of shorthand assignment operators has three advantages: ◦ 1. What appears on the left-hand side need not be repeated and therefore it becomes easier to write. ◦ 2. The statement is more concise and easier to read. ◦ 3. The statement is more efficient. 11
  • 12. 3.6 Increment and decrement operators  C provides two unusual operators for incrementing and decrementing variables.  The increment operator ++ adds 1 to its operand, while the decrement operator -- subtracts 1.  The unusual aspect is that ++ and -- may be used either as prefix operators (before the variable, as in ++n), or postfix operators (after the variable: n++).  In both cases, the effect is to increment n. But the expression ++n increments n before its value is used, while n++ increments n after its value has been used. 12
  • 13. The increment and decrement operators can be used in complex statements. Example: m=n++ -j +10;  Consider the expression m = - n++ ;  The precedence of ++ and – operators are the same as those of unary + and -.  The associatively of them is right to left.  m = - n++; is equivalent to m = - (n++) 13
  • 14. 3.7 Conditional operator  a ternary operator pair “? : ” is available in C to construct conditional expressions of the form expr1 ? expr2 : expr3  the expression expr1 is evaluated first. If it is non-zero (true), then the expression expr2 is evaluated, and that is the value of the conditional expression. Otherwise expr3 is evaluated, and that is the value. Only one of expr2 and expr3 is evaluated. 14
  • 15. z = (a > b) ? a : b; /* z = max(a, b) */ 15
  • 16. 3.9 Special operators  1. The Comma Operator  The comma operator can be used to link the related expressions together. A comma-linked list of expressions is evaluated left to right and the value of right-most expression is the value of the combined expression. For example, the statement  value = (x=10, y=5, x+y);  first assigns the value 10 to x, then assigns 5 to y, and finally assigns 15 to value. Since comma operator has the lowest precedence of all operators, the parentheses are necessary. 16
  • 17. 3.14 Type conversions in expressions  1. Implicit Type Conversion  C permits mixing of constants and variables of different types in an expression. C automatically converts any intermediate values to the proper type so that the expression can be evaluated without loosing any significance. This automatic conversion is known as implicit type conversion.  The rule of type conversion: the lower type is automatically converted to the higher type. 17
  • 18. 3.13 Some Computational Problems  When expressions include real values, then it is important to take necessary precautions to guard against certain computational errors. For example, consider the following statements: ◦ a = 1.0 / 3.0; ◦ b = a * 3.0;  There is no guarantee that the value of b will equal 1.  Another problem is division by zero.  The third problem is to avoid overflow and underflow errors. 18
  • 19. 3.15 Operator precedence and Associativity  Rules of Precedence and Associativity ◦ (1)Precedence rules decides the order in which different operators are applied. ◦ (2)Associativity rule decide the order in which multiple occurrences of the same level operator are applied.  Table3.8 on page71 shows the summary of C Operators.  for example,  a = i +1== j || k and 3 != x 19
  • 20. THANKS 20