SlideShare a Scribd company logo
Chapter 4: Basic C Operators
  In this chapter, you will learn about:
     Arithmetic operators
        Unary operators
        Binary operators
     Assignment operators
     Equalities and relational operators
     Logical operators
     Conditional operator




Principles of Programming - NI July2005    1
Arithmetic Operators I
  In C, we have the following operators (note
  that all these example are using 9 as the
  value of its first operand)




Principles of Programming - NI July2005   2
Arithmetic Operators II
  There are 2 types of arithmetic operators
  in C:
     unary operators
        operators that require only one operand.
     binary operators.
        operators that require two operands.




Principles of Programming - NI July2005   3
Unary Operator
C Operation          Operator     Example
Positive                +          a = +3
Negative                -          b = -a
Increment              ++           i++
Decrement               --          i--

  The first assigns positive 3 to a
  The second assigns the negative value of a to b.
  i++ is equivalent to i = i + 1
  i-- is equivalent to i = i-1


Principles of Programming - NI July2005   4
PRE- / POST-Increment
  It is also possible to use ++i and --i instead of
  i++ and i--
  However, the two forms have a slightly yet
  important difference.
  Consider this example:
      int a = 9;
      printf(ā€œ%dnā€, a++);
      printf(ā€œ%dā€, a);
  The output would be:
   9
   10
Principles of Programming - NI July2005   5
PRE- / POST-Increment cont…
  But if we have:
      int a = 9;
      printf(ā€œ%dnā€, ++a);
      printf(ā€œ%dā€, a);
  The output would be:
   10
   10
  a++ would return the current value of a and
  then increment the value of a
  ++a on the other hand increment the value of
  a before returning the value

Principles of Programming - NI July2005   6
The following table illustrates the difference between the prefix and postfix
 modes of the increment and decrement operator.


                          int R = 10, count=10;

   ++ Or --                   Equivalent                      R value            Count
  Statement                   Statements                                         value
R = count++;             R = count;
                                                                  10              11
                         count = count + 1
R = ++count;             count = count + 1;
                                                                  11              11
                         R = count;
R = count --;            R = count;
                                                                  10              9
                         count = count – 1;
R = --count;             Count = count – 1;
                                                                   9              9
                         R = count;


 Principles of Programming - NI July2005                             7
Binary Operators
C Operation          Operator             Example:
Addition                 +                  a+3
Subtraction              -                  a-6
Multiplication           *                  a*b
Division                 /                  a/c
Modulus                 %                   a%x

  The division of variables of type int will always
  produce a variable of type int as the result.
  You could only use modulus (%) operation
  on int variables.

Principles of Programming - NI July2005    8
Assignment Operators
  Assignment operators are used to combine the
  '=' operator with one of the binary arithmetic
  operators
  In the following slide, All operations starting from
      c=9
      Operator    Example     Equivalent   Results
                              Statement
         +=       c += 7     c=c+7         c = 16
         -=        c -= 8    c=c–8          c=1
         *=       c *= 10    c = c * 10    c = 90
         /=        c /= 5     c=c/5         c=1
         %=       c %= 5     c=c%5          c=4
Principles of Programming - NI July2005    9
Precedence Rules
  Precedence rules come into play when there is a mixed
  of arithmetic operators in one statement. For example:
  x = 3 * a - ++b%3;
  The rules specify which of the operators will be
  evaluated first.

  Precedence         Operator             Associativity
  Level
  1 (highest)        ()                     left to right
  2                  unary                  right to left
  3                  * / %                  left to right
  4                  + -                    left to right
  5 (lowest)         = += -= *= /= %=       right to left


Principles of Programming - NI July2005     10
Precedence Rules cont…
  For example: x = 3 * a - ++b % 3;
   how would this statement be evaluated?

  If we intend to have the statement evaluated
  differently from the way specified by the
  precedence rules, we need to specify it using
  parentheses ( )
  Using parenthesis, we will have
          x = 3 * ((a - ++b)%3);
  The expression inside a parentheses will be
  evaluated first.
  The inner parentheses will be evaluated
  earlier compared to the outer parentheses.

Principles of Programming - NI July2005     11
Equality and Relational Operators
 Equality Operators:
   Operator        Example       Meaning
    ==              x == y       x is equal to y
    !=              x != y       x is not equal to y

 Relational Operators:
   Operator        Example       Meaning
    >              x>y           x is greater than y
    <              x<y           x is less than y
    >=             x >= y        x is greater than or equal to y
    <=             x <= y        x is less than or equal to y




Principles of Programming - NI July2005      12
Logical Operators
  Logical operators are useful when we want to
  test multiple conditions.
  There are 3 types of logical operators and they
  work the same way as the boolean AND, OR and
  NOT operators.
  && - Logical AND
    All the conditions must be true for the whole
    expression to be true.
    Example: if (a == 10 && b == 9 && d == 1)
    means the if statement is only true when a ==
    10 and b == 9 and d == 1.

Principles of Programming - NI July2005   13
Logical Operators cont…
  || - Logical OR
     The truth of one condition is enough to make
     the whole expression true.
     Example: if (a == 10 || b == 9 || d == 1)
     means the if statement is true when either
     one of a, b or d has the right value.
  ! - Logical NOT (also called logical negation)
     Reverse the meaning of a condition
     Example: if (!(points > 90))
     means if points not bigger than 90.

Principles of Programming - NI July2005   14
Conditional Operator
  The conditional operator (?:) is used to
  simplify an if/else statement.
  Syntax:
  Condition ? Expression1 : Expression2
  The statement above is equivalent to:
       if (Condition)
            Expression1
       else
            Expression2


Principles of Programming - NI July2005   15
Conditional Operator cont…
  Example 1:
  if/else statement:
   if (total > 60)
        grade = ā€˜P’
  else
        grade = ā€˜F’;
  conditional statement:
  total > 60 ? grade = ā€˜P’: grade = ā€˜F’;
                     OR
   grade = total > 60 ? ā€˜P’: ā€˜F’;
Principles of Programming - NI July2005   16
Conditional Operator cont…
Example 2:
if/else statement:
if (total > 60)
     printf(ā€œPassed!!nā€);
else
     printf(ā€œFailed!!nā€);

Conditional Statement:
printf(ā€œ%s!!nā€, total > 60? ā€œPassedā€: ā€œFailedā€);

Principles of Programming - NI July2005   17
SUMMARY
  This chapter exposed you the operators used
  in C
     Arithmetic operators
     Assignment operators
     Equalities and relational operators
     Logical operators
     Conditional operator
  Precedence levels come into play when there
  is a mixed of arithmetic operators in one
  statement.
  Pre/post fix - effects the result of statement


Principles of Programming - NI July2005    18

More Related Content

PPT
13 Boolean Algebra
Praveen M Jigajinni
Ā 
PPT
Operators in C Programming
programming9
Ā 
PPTX
Unit 4 combinational circuit
Kalai Selvi
Ā 
PPTX
Operator in c programming
Manoj Tyagi
Ā 
PPTX
Data types in C
Tarun Sharma
Ā 
PPTX
Functions in C
Kamal Acharya
Ā 
PPTX
Operators
Krishna Kumar Pankaj
Ā 
DOCX
some basic C programs with outputs
KULDEEPSING PATIL
Ā 
13 Boolean Algebra
Praveen M Jigajinni
Ā 
Operators in C Programming
programming9
Ā 
Unit 4 combinational circuit
Kalai Selvi
Ā 
Operator in c programming
Manoj Tyagi
Ā 
Data types in C
Tarun Sharma
Ā 
Functions in C
Kamal Acharya
Ā 
some basic C programs with outputs
KULDEEPSING PATIL
Ā 

What's hot (20)

PDF
Binary codes
Revathi Subramaniam
Ā 
PPTX
Digital and logic designs presentation
Haya Butt
Ā 
PPT
Structure of a C program
David Livingston J
Ā 
PPTX
Operators and Expressions
Munazza-Mah-Jabeen
Ā 
PPTX
C Programming : Pointers and Strings
Selvaraj Seerangan
Ā 
PPTX
Extended relational algebra
1Arun_Pandey
Ā 
PPTX
SOP POS, Minterm and Maxterm
Self-employed
Ā 
PPTX
C tokens
Manu1325
Ā 
PPT
Operator Overloading
Nilesh Dalvi
Ā 
PPTX
Adder ppt
Avinash Jadhav
Ā 
PPTX
Call by value
Dharani G
Ā 
PPTX
C Tokens
Ripon Hossain
Ā 
PPTX
Control statements in c
Sathish Narayanan
Ā 
PPTX
Presentation on Function in C Programming
Shuvongkor Barman
Ā 
PPTX
Operators in python
deepalishinkar1
Ā 
PPT
Logic gates
prasanna chitra
Ā 
PDF
Arrays in C++
Maliha Mehr
Ā 
PPT
Array in c
Ravi Gelani
Ā 
PPTX
Operators in C#
anshika shrivastav
Ā 
Binary codes
Revathi Subramaniam
Ā 
Digital and logic designs presentation
Haya Butt
Ā 
Structure of a C program
David Livingston J
Ā 
Operators and Expressions
Munazza-Mah-Jabeen
Ā 
C Programming : Pointers and Strings
Selvaraj Seerangan
Ā 
Extended relational algebra
1Arun_Pandey
Ā 
SOP POS, Minterm and Maxterm
Self-employed
Ā 
C tokens
Manu1325
Ā 
Operator Overloading
Nilesh Dalvi
Ā 
Adder ppt
Avinash Jadhav
Ā 
Call by value
Dharani G
Ā 
C Tokens
Ripon Hossain
Ā 
Control statements in c
Sathish Narayanan
Ā 
Presentation on Function in C Programming
Shuvongkor Barman
Ā 
Operators in python
deepalishinkar1
Ā 
Logic gates
prasanna chitra
Ā 
Arrays in C++
Maliha Mehr
Ā 
Array in c
Ravi Gelani
Ā 
Operators in C#
anshika shrivastav
Ā 
Ad

Viewers also liked (7)

PPT
Slides 2-basic sql
Anuja Lad
Ā 
PPT
Final exam review answer(networking)
welcometofacebook
Ā 
PPT
Basic networking hardware pre final 1
Anuja Lad
Ā 
PDF
Top 100 SQL Interview Questions and Answers
iimjobs and hirist
Ā 
DOC
Best sql plsql material
pitchaiah yechuri
Ā 
DOC
Sql queries with answers
vijaybusu
Ā 
PPT
Sql ppt
Anuja Lad
Ā 
Slides 2-basic sql
Anuja Lad
Ā 
Final exam review answer(networking)
welcometofacebook
Ā 
Basic networking hardware pre final 1
Anuja Lad
Ā 
Top 100 SQL Interview Questions and Answers
iimjobs and hirist
Ā 
Best sql plsql material
pitchaiah yechuri
Ā 
Sql queries with answers
vijaybusu
Ā 
Sql ppt
Anuja Lad
Ā 
Ad

Similar to Basic c operators (20)

PPT
Operation and expression in c++
Online
Ā 
PDF
Arithmetic instructions
Learn By Watch
Ā 
PPTX
c programme
MitikaAnjel
Ā 
PPT
Operator & Expression in c++
bajiajugal
Ā 
PPS
C programming session 02
Dushmanta Nath
Ā 
PPS
02 iec t1_s1_oo_ps_session_02
Niit Care
Ā 
PDF
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
Ā 
PPT
FP 201 Unit 2 - Part 3
rohassanie
Ā 
PPTX
Operators and expressions
vishaljot_kaur
Ā 
PPT
Mesics lecture 4 c operators and experssions
eShikshak
Ā 
DOC
Unit 4
rohassanie
Ā 
PPS
C programming session 02
AjayBahoriya
Ā 
PPTX
Working with IDE
Nurul Zakiah Zamri Tan
Ā 
PPTX
Operators-computer programming and utilzation
Kaushal Patel
Ā 
PPTX
Operators and Expression
shubham_jangid
Ā 
PPT
Java 2
Preethi Nambiar
Ā 
PPT
Java - Operators
Preethi Nambiar
Ā 
PDF
Lecture03(c expressions & operators)
Dhaka University of Engineering & Technology(DUET)
Ā 
DOC
Report on c
jasmeen kr
Ā 
PDF
C sharp chap3
Mukesh Tekwani
Ā 
Operation and expression in c++
Online
Ā 
Arithmetic instructions
Learn By Watch
Ā 
c programme
MitikaAnjel
Ā 
Operator & Expression in c++
bajiajugal
Ā 
C programming session 02
Dushmanta Nath
Ā 
02 iec t1_s1_oo_ps_session_02
Niit Care
Ā 
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
Ā 
FP 201 Unit 2 - Part 3
rohassanie
Ā 
Operators and expressions
vishaljot_kaur
Ā 
Mesics lecture 4 c operators and experssions
eShikshak
Ā 
Unit 4
rohassanie
Ā 
C programming session 02
AjayBahoriya
Ā 
Working with IDE
Nurul Zakiah Zamri Tan
Ā 
Operators-computer programming and utilzation
Kaushal Patel
Ā 
Operators and Expression
shubham_jangid
Ā 
Java 2
Preethi Nambiar
Ā 
Java - Operators
Preethi Nambiar
Ā 
Lecture03(c expressions & operators)
Dhaka University of Engineering & Technology(DUET)
Ā 
Report on c
jasmeen kr
Ā 
C sharp chap3
Mukesh Tekwani
Ā 

More from Anuja Lad (20)

DOCX
Important topic in board exams
Anuja Lad
Ā 
PDF
Data communication
Anuja Lad
Ā 
PPT
Data communication intro
Anuja Lad
Ā 
DOCX
Questions from chapter 1 data communication and networking
Anuja Lad
Ā 
DOC
T y b com question paper of mumbai university
Anuja Lad
Ā 
DOCX
Questions from chapter 1 data communication and networking
Anuja Lad
Ā 
DOC
T y b com question paper of mumbai university
Anuja Lad
Ā 
PPT
Basic networking hardware pre final 1
Anuja Lad
Ā 
PDF
Data communication
Anuja Lad
Ā 
PPT
Data communication intro
Anuja Lad
Ā 
PPT
Intro net 91407
Anuja Lad
Ā 
PPT
Itmg360 chapter one_v05
Anuja Lad
Ā 
PPT
Mysqlppt3510
Anuja Lad
Ā 
PPT
Lab 4 excel basics
Anuja Lad
Ā 
PPT
Mysql2
Anuja Lad
Ā 
PDF
Introductionto excel2007
Anuja Lad
Ā 
PPT
C tutorial
Anuja Lad
Ā 
PPT
C
Anuja Lad
Ā 
PPT
5 intro to networking
Anuja Lad
Ā 
PPT
1 introduction-to-computer-networking
Anuja Lad
Ā 
Important topic in board exams
Anuja Lad
Ā 
Data communication
Anuja Lad
Ā 
Data communication intro
Anuja Lad
Ā 
Questions from chapter 1 data communication and networking
Anuja Lad
Ā 
T y b com question paper of mumbai university
Anuja Lad
Ā 
Questions from chapter 1 data communication and networking
Anuja Lad
Ā 
T y b com question paper of mumbai university
Anuja Lad
Ā 
Basic networking hardware pre final 1
Anuja Lad
Ā 
Data communication
Anuja Lad
Ā 
Data communication intro
Anuja Lad
Ā 
Intro net 91407
Anuja Lad
Ā 
Itmg360 chapter one_v05
Anuja Lad
Ā 
Mysqlppt3510
Anuja Lad
Ā 
Lab 4 excel basics
Anuja Lad
Ā 
Mysql2
Anuja Lad
Ā 
Introductionto excel2007
Anuja Lad
Ā 
C tutorial
Anuja Lad
Ā 
5 intro to networking
Anuja Lad
Ā 
1 introduction-to-computer-networking
Anuja Lad
Ā 

Recently uploaded (20)

PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
Ā 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
Ā 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
Ā 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
Ā 
PDF
Architecture of the Future (09152021)
EdwardMeyman
Ā 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
Ā 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
Ā 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
PDF
Doc9.....................................
SofiaCollazos
Ā 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
Ā 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
Ā 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
Ā 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
Ā 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
Ā 
Architecture of the Future (09152021)
EdwardMeyman
Ā 
REPORT: Heating appliances market in Poland 2024
SPIUG
Ā 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
Ā 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
Ā 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
Doc9.....................................
SofiaCollazos
Ā 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
Ā 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 

Basic c operators

  • 1. Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional operator Principles of Programming - NI July2005 1
  • 2. Arithmetic Operators I In C, we have the following operators (note that all these example are using 9 as the value of its first operand) Principles of Programming - NI July2005 2
  • 3. Arithmetic Operators II There are 2 types of arithmetic operators in C: unary operators operators that require only one operand. binary operators. operators that require two operands. Principles of Programming - NI July2005 3
  • 4. Unary Operator C Operation Operator Example Positive + a = +3 Negative - b = -a Increment ++ i++ Decrement -- i-- The first assigns positive 3 to a The second assigns the negative value of a to b. i++ is equivalent to i = i + 1 i-- is equivalent to i = i-1 Principles of Programming - NI July2005 4
  • 5. PRE- / POST-Increment It is also possible to use ++i and --i instead of i++ and i-- However, the two forms have a slightly yet important difference. Consider this example: int a = 9; printf(ā€œ%dnā€, a++); printf(ā€œ%dā€, a); The output would be: 9 10 Principles of Programming - NI July2005 5
  • 6. PRE- / POST-Increment cont… But if we have: int a = 9; printf(ā€œ%dnā€, ++a); printf(ā€œ%dā€, a); The output would be: 10 10 a++ would return the current value of a and then increment the value of a ++a on the other hand increment the value of a before returning the value Principles of Programming - NI July2005 6
  • 7. The following table illustrates the difference between the prefix and postfix modes of the increment and decrement operator. int R = 10, count=10; ++ Or -- Equivalent R value Count Statement Statements value R = count++; R = count; 10 11 count = count + 1 R = ++count; count = count + 1; 11 11 R = count; R = count --; R = count; 10 9 count = count – 1; R = --count; Count = count – 1; 9 9 R = count; Principles of Programming - NI July2005 7
  • 8. Binary Operators C Operation Operator Example: Addition + a+3 Subtraction - a-6 Multiplication * a*b Division / a/c Modulus % a%x The division of variables of type int will always produce a variable of type int as the result. You could only use modulus (%) operation on int variables. Principles of Programming - NI July2005 8
  • 9. Assignment Operators Assignment operators are used to combine the '=' operator with one of the binary arithmetic operators In the following slide, All operations starting from c=9 Operator Example Equivalent Results Statement += c += 7 c=c+7 c = 16 -= c -= 8 c=c–8 c=1 *= c *= 10 c = c * 10 c = 90 /= c /= 5 c=c/5 c=1 %= c %= 5 c=c%5 c=4 Principles of Programming - NI July2005 9
  • 10. Precedence Rules Precedence rules come into play when there is a mixed of arithmetic operators in one statement. For example: x = 3 * a - ++b%3; The rules specify which of the operators will be evaluated first. Precedence Operator Associativity Level 1 (highest) () left to right 2 unary right to left 3 * / % left to right 4 + - left to right 5 (lowest) = += -= *= /= %= right to left Principles of Programming - NI July2005 10
  • 11. Precedence Rules cont… For example: x = 3 * a - ++b % 3; how would this statement be evaluated? If we intend to have the statement evaluated differently from the way specified by the precedence rules, we need to specify it using parentheses ( ) Using parenthesis, we will have x = 3 * ((a - ++b)%3); The expression inside a parentheses will be evaluated first. The inner parentheses will be evaluated earlier compared to the outer parentheses. Principles of Programming - NI July2005 11
  • 12. Equality and Relational Operators Equality Operators: Operator Example Meaning == x == y x is equal to y != x != y x is not equal to y Relational Operators: Operator Example Meaning > x>y x is greater than y < x<y x is less than y >= x >= y x is greater than or equal to y <= x <= y x is less than or equal to y Principles of Programming - NI July2005 12
  • 13. Logical Operators Logical operators are useful when we want to test multiple conditions. There are 3 types of logical operators and they work the same way as the boolean AND, OR and NOT operators. && - Logical AND All the conditions must be true for the whole expression to be true. Example: if (a == 10 && b == 9 && d == 1) means the if statement is only true when a == 10 and b == 9 and d == 1. Principles of Programming - NI July2005 13
  • 14. Logical Operators cont… || - Logical OR The truth of one condition is enough to make the whole expression true. Example: if (a == 10 || b == 9 || d == 1) means the if statement is true when either one of a, b or d has the right value. ! - Logical NOT (also called logical negation) Reverse the meaning of a condition Example: if (!(points > 90)) means if points not bigger than 90. Principles of Programming - NI July2005 14
  • 15. Conditional Operator The conditional operator (?:) is used to simplify an if/else statement. Syntax: Condition ? Expression1 : Expression2 The statement above is equivalent to: if (Condition) Expression1 else Expression2 Principles of Programming - NI July2005 15
  • 16. Conditional Operator cont… Example 1: if/else statement: if (total > 60) grade = ā€˜P’ else grade = ā€˜F’; conditional statement: total > 60 ? grade = ā€˜P’: grade = ā€˜F’; OR grade = total > 60 ? ā€˜P’: ā€˜F’; Principles of Programming - NI July2005 16
  • 17. Conditional Operator cont… Example 2: if/else statement: if (total > 60) printf(ā€œPassed!!nā€); else printf(ā€œFailed!!nā€); Conditional Statement: printf(ā€œ%s!!nā€, total > 60? ā€œPassedā€: ā€œFailedā€); Principles of Programming - NI July2005 17
  • 18. SUMMARY This chapter exposed you the operators used in C Arithmetic operators Assignment operators Equalities and relational operators Logical operators Conditional operator Precedence levels come into play when there is a mixed of arithmetic operators in one statement. Pre/post fix - effects the result of statement Principles of Programming - NI July2005 18