SlideShare a Scribd company logo
Increment & Decrement operators (Postfix and Prefix) Ms.Nita Arora KHMS
Increment operator (++) Increases the value stored in a variable by 1  a++ a+=1 a=a+1 are all equivalent in functionality.
Increment operator (++) can be used in PREFIX and POSTFIX form. int B=3; int A=++B; //output B=4 //  A=4 int B=3; int A=B++; //output B=4 //  A=3
Decrement operator (--) Decreases the value stored in a variable by 1  a-- a - =1 a=a-1 are all equivalent in functionality.
Decrement operator (--) can be used in  PREFIX  and  POSTFIX  form. int B=3; int A=--B; //output B=2 //  A=2 int B=3; int A=B- -; //output B=2 //  A=3
Priority of Operators and Associativity Left Comma , 11 Right Assignment = += -= *= /= %= 10 Right Conditional ?: 9 Left Logical  Op. && || 8 Left Relational Op. ==  != 7 Left Relational Op. < <= >= > 6 Left Arithmetic Op. + - 5 Left Arithmetic Op. * / % 4 Right ++ -- ! & * (type) + - 3 Left ()[]->sizeof 2 Left Scope :: 1 associativity Description Operator Priority
Associativity  In case there are several operators of same priority, which one must be evaluated before- Leftmost Rightmost
Evaluation of expressions involving ++ and -- operators in postfix and prefix form PROBLEM AREA
Examples
#include <iostream.h> #include <conio.h> void main() {  clrscr(); cout <<&quot;\n************* EVALUATION OF EXPRESSIONS *************** \n\n&quot;; int a=10,b=20,c=30; cout<<&quot;a=&quot;<<a<<&quot;  b=&quot;<<b<<&quot;  c=&quot;<<c; int z=(a++)*c/a+b; cout <<&quot;\nz=(a++ )*c/a+b  =  &quot;; getch(); cout<<z; } Example 1
Example 2 #include <iostream.h> #include <conio.h> void main() {clrscr(); cout <<&quot;\n** EVALUATION OF EXPRESSIONS ***\n\n&quot;; int  a=10,b=20,c=30; cout<<&quot;a=&quot;<<a<<&quot;  b=&quot;<<b<<&quot;  c=&quot;<<c; z=++a*c/a+b; cout <<&quot;\nz=++a*c/a+b  =  &quot;<<; getch(); cout<<z; }
#include <iostream.h> #include <conio.h> void main() {clrscr(); cout <<&quot;\n************* EVALUATION OF EXPRESSIONS ****************\n\n&quot;; int  a=1,b=2,c=3; cout<<&quot;a=&quot;<<a<<&quot;  b=&quot;<<b<<&quot;  c=&quot;<<c; z= b+ c^a * ++b ; cout <<&quot;\nz=b+c^a * ++b;  =  &quot;; cout <<&quot;\nAnswer is :(3+3)^(1*3)  \n&quot;; cout <<&quot;\n  :(6)^(3)  \n&quot;; cout <<&quot;\nIn Binary :(110) XOR (011)  \n&quot;; cout <<&quot;\n  :(101)  \n&quot;; cout <<&quot;\nIn Decimal Answer is :  \n&quot;; getch(); cout<<z; } Example 3
#include <iostream.h> #include <conio.h> void main() {clrscr(); cout <<&quot;\n* EVALUATION OF EXPRESSIONS *\n\n&quot;; z=45; int q=45; cout<<&quot;\nq=&quot;<<q; cout<<&quot;\n-q--=&quot;<<-q--; cout<<&quot;q=  &quot; <<q; getch(); } Example 4
6.  What is the screen output?   int  a=20; a += a++  +  ++a ; cout << a; 5.  What is the screen output?    int i, j, k, m, ans;      i = 0;      j = -1;      k = 0;      m = 1;;      ans = i++  &&  ++j   ||  k  ||  m++;      cout<<ans;  4.  What is the screen output?      int i, j, k, ans;      i = 1;      j = 2;      k = 3;      ans = ++i  *   j  -   k--;      cout<<ans; 3.  What is the screen output?      int i, j, k, ans;      i = 1;      j = 2;      k = 3;      ans = i++  *   j  -   --k;      cout<<ans; 2.  What is the screen output?      int a, b;      a = 6;      b = ++a -1;      cout<<&quot;a =  &quot; << a << endl;      cout<<&quot;b =  &quot; << b << endl; 1.  What is the screen output?      int a, b;      a = 6;      b = a++ -1;      cout<<&quot;a =  &quot; << a <<endl;      cout<<&quot;b =  &quot; << b <<endl;  
Evaluate the following c++ expressions where a, b, c are integers and d and f are floating point numbers. The values are a = 5, b=3 and d=1.5 f=a+b/a; c=d*a+b; c=a++ * d +a; f=++b * b – a; c=a-(b++) * (--d);
Do you have any QUESTIONS ?

More Related Content

PPTX
Unit I - Evaluation of expression
PDF
Time and Space Complexity
PPTX
Deque and its applications
PPTX
Arithmetic Expression
PPT
standard template library(STL) in C++
PPT
Python Dictionaries and Sets
PPTX
Automata theory -RE to NFA-ε
PPTX
Boolean and conditional logic in Python
Unit I - Evaluation of expression
Time and Space Complexity
Deque and its applications
Arithmetic Expression
standard template library(STL) in C++
Python Dictionaries and Sets
Automata theory -RE to NFA-ε
Boolean and conditional logic in Python

What's hot (20)

PPTX
The Stack And Recursion
PDF
Functions and modules in python
PPT
Infix prefix postfix
PPT
Function overloading(c++)
PPTX
String Builder & String Buffer (Java Programming)
PPT
17. Trees and Graphs
PPTX
Conditional statement in c
PPTX
Pointer to function 1
PPTX
Arrays in Data Structure and Algorithm
PPTX
Infix to postfix conversion
PPT
PPTX
Operators and expressions in C++
PPTX
Loop(for, while, do while) condition Presentation
PPT
Operators in C++
PPTX
Stack Data Structure
PPT
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
PPT
Unit 4 external sorting
PPTX
Library functions in c++
DOCX
Data Structure in C (Lab Programs)
PDF
Object oriented programming c++
The Stack And Recursion
Functions and modules in python
Infix prefix postfix
Function overloading(c++)
String Builder & String Buffer (Java Programming)
17. Trees and Graphs
Conditional statement in c
Pointer to function 1
Arrays in Data Structure and Algorithm
Infix to postfix conversion
Operators and expressions in C++
Loop(for, while, do while) condition Presentation
Operators in C++
Stack Data Structure
358 33 powerpoint-slides_11-efficient-binary-trees_chapter-11
Unit 4 external sorting
Library functions in c++
Data Structure in C (Lab Programs)
Object oriented programming c++
Ad

Viewers also liked (20)

DOCX
Conversion from infix to prefix using stack
PDF
Infix to Prefix (Conversion, Evaluation, Code)
PPTX
Infix to postfix
PPT
Conversion of Infix To Postfix Expressions
DOC
Infix to-postfix examples
 
PPTX
c programme
PPTX
Infix-Postfix expression conversion
PPTX
CHAPTER 3
PPT
Can my English course be translated to Tamil language?
PPT
robotics workshop Aug.09
PPTX
Programming maintenance - Programming methodology
PPT
A message of stephen covey
PDF
Programming methodology lecture01
PDF
Programming methodology lecture26
Conversion from infix to prefix using stack
Infix to Prefix (Conversion, Evaluation, Code)
Infix to postfix
Conversion of Infix To Postfix Expressions
Infix to-postfix examples
 
c programme
Infix-Postfix expression conversion
CHAPTER 3
Can my English course be translated to Tamil language?
robotics workshop Aug.09
Programming maintenance - Programming methodology
A message of stephen covey
Programming methodology lecture01
Programming methodology lecture26
Ad

Similar to Prefix Postfix (20)

PPT
Lecture 3
PPT
Lecture#5 Operators in C++
DOCX
Labsheet2 stud
PPT
C Sharp Jn (2)
PPT
C Sharp Jn (2)
DOC
Labsheet2
PPTX
C++ Programming Basics.pptx
PPT
C++ chapter 2
PDF
Lab Manual IV (1).pdf on C++ Programming practice
PPTX
Cs1123 4 variables_constants
PPTX
Lecture05 operator overloading-and_exception_handling
PDF
check the modifed code now you will get all operations done.termin.pdf
PPT
Pointer
PPSX
Stacks Implementation and Examples
PPT
Arrays
PPT
Lecture17
PPT
C++lecture9
PDF
C++ Course - Lesson 2
PPT
Chapter 3 Expressions and Inteactivity
PPTX
Data Structure and Algorithms by Sabeen Memon03.pptx
Lecture 3
Lecture#5 Operators in C++
Labsheet2 stud
C Sharp Jn (2)
C Sharp Jn (2)
Labsheet2
C++ Programming Basics.pptx
C++ chapter 2
Lab Manual IV (1).pdf on C++ Programming practice
Cs1123 4 variables_constants
Lecture05 operator overloading-and_exception_handling
check the modifed code now you will get all operations done.termin.pdf
Pointer
Stacks Implementation and Examples
Arrays
Lecture17
C++lecture9
C++ Course - Lesson 2
Chapter 3 Expressions and Inteactivity
Data Structure and Algorithms by Sabeen Memon03.pptx

More from Kulachi Hansraj Model School Ashok Vihar (13)

Recently uploaded (20)

PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PDF
MSPs in 10 Words - Created by US MSP Network
PDF
Unit 1 Cost Accounting - Cost sheet
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PDF
How to Get Business Funding for Small Business Fast
PDF
Nidhal Samdaie CV - International Business Consultant
PPTX
HR Introduction Slide (1).pptx on hr intro
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PPTX
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PDF
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
PPTX
5 Stages of group development guide.pptx
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
Training And Development of Employee .pdf
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
DOCX
Business Management - unit 1 and 2
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
Belch_12e_PPT_Ch18_Accessible_university.pptx
MSPs in 10 Words - Created by US MSP Network
Unit 1 Cost Accounting - Cost sheet
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
How to Get Business Funding for Small Business Fast
Nidhal Samdaie CV - International Business Consultant
HR Introduction Slide (1).pptx on hr intro
New Microsoft PowerPoint Presentation - Copy.pptx
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
ICG2025_ICG 6th steering committee 30-8-24.pptx
kom-180-proposal-for-a-directive-amending-directive-2014-45-eu-and-directive-...
5 Stages of group development guide.pptx
COST SHEET- Tender and Quotation unit 2.pdf
Training And Development of Employee .pdf
Lecture (1)-Introduction.pptx business communication
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
Business Management - unit 1 and 2
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
340036916-American-Literature-Literary-Period-Overview.ppt

Prefix Postfix

  • 1. Increment & Decrement operators (Postfix and Prefix) Ms.Nita Arora KHMS
  • 2. Increment operator (++) Increases the value stored in a variable by 1 a++ a+=1 a=a+1 are all equivalent in functionality.
  • 3. Increment operator (++) can be used in PREFIX and POSTFIX form. int B=3; int A=++B; //output B=4 // A=4 int B=3; int A=B++; //output B=4 // A=3
  • 4. Decrement operator (--) Decreases the value stored in a variable by 1 a-- a - =1 a=a-1 are all equivalent in functionality.
  • 5. Decrement operator (--) can be used in PREFIX and POSTFIX form. int B=3; int A=--B; //output B=2 // A=2 int B=3; int A=B- -; //output B=2 // A=3
  • 6. Priority of Operators and Associativity Left Comma , 11 Right Assignment = += -= *= /= %= 10 Right Conditional ?: 9 Left Logical Op. && || 8 Left Relational Op. == != 7 Left Relational Op. < <= >= > 6 Left Arithmetic Op. + - 5 Left Arithmetic Op. * / % 4 Right ++ -- ! & * (type) + - 3 Left ()[]->sizeof 2 Left Scope :: 1 associativity Description Operator Priority
  • 7. Associativity In case there are several operators of same priority, which one must be evaluated before- Leftmost Rightmost
  • 8. Evaluation of expressions involving ++ and -- operators in postfix and prefix form PROBLEM AREA
  • 10. #include <iostream.h> #include <conio.h> void main() { clrscr(); cout <<&quot;\n************* EVALUATION OF EXPRESSIONS *************** \n\n&quot;; int a=10,b=20,c=30; cout<<&quot;a=&quot;<<a<<&quot; b=&quot;<<b<<&quot; c=&quot;<<c; int z=(a++)*c/a+b; cout <<&quot;\nz=(a++ )*c/a+b = &quot;; getch(); cout<<z; } Example 1
  • 11. Example 2 #include <iostream.h> #include <conio.h> void main() {clrscr(); cout <<&quot;\n** EVALUATION OF EXPRESSIONS ***\n\n&quot;; int a=10,b=20,c=30; cout<<&quot;a=&quot;<<a<<&quot; b=&quot;<<b<<&quot; c=&quot;<<c; z=++a*c/a+b; cout <<&quot;\nz=++a*c/a+b = &quot;<<; getch(); cout<<z; }
  • 12. #include <iostream.h> #include <conio.h> void main() {clrscr(); cout <<&quot;\n************* EVALUATION OF EXPRESSIONS ****************\n\n&quot;; int a=1,b=2,c=3; cout<<&quot;a=&quot;<<a<<&quot; b=&quot;<<b<<&quot; c=&quot;<<c; z= b+ c^a * ++b ; cout <<&quot;\nz=b+c^a * ++b; = &quot;; cout <<&quot;\nAnswer is :(3+3)^(1*3) \n&quot;; cout <<&quot;\n :(6)^(3) \n&quot;; cout <<&quot;\nIn Binary :(110) XOR (011) \n&quot;; cout <<&quot;\n :(101) \n&quot;; cout <<&quot;\nIn Decimal Answer is : \n&quot;; getch(); cout<<z; } Example 3
  • 13. #include <iostream.h> #include <conio.h> void main() {clrscr(); cout <<&quot;\n* EVALUATION OF EXPRESSIONS *\n\n&quot;; z=45; int q=45; cout<<&quot;\nq=&quot;<<q; cout<<&quot;\n-q--=&quot;<<-q--; cout<<&quot;q= &quot; <<q; getch(); } Example 4
  • 14. 6.  What is the screen output? int a=20; a += a++ + ++a ; cout << a; 5.  What is the screen output?    int i, j, k, m, ans;      i = 0;      j = -1;      k = 0;      m = 1;;      ans = i++  &&  ++j   ||  k  ||  m++;      cout<<ans; 4.  What is the screen output?      int i, j, k, ans;      i = 1;      j = 2;      k = 3;      ans = ++i  *   j  -   k--;      cout<<ans; 3.  What is the screen output?      int i, j, k, ans;      i = 1;      j = 2;      k = 3;      ans = i++  *   j  -   --k;      cout<<ans; 2.  What is the screen output?      int a, b;      a = 6;      b = ++a -1;      cout<<&quot;a =  &quot; << a << endl;      cout<<&quot;b =  &quot; << b << endl; 1.  What is the screen output?      int a, b;      a = 6;      b = a++ -1;      cout<<&quot;a =  &quot; << a <<endl;      cout<<&quot;b =  &quot; << b <<endl;  
  • 15. Evaluate the following c++ expressions where a, b, c are integers and d and f are floating point numbers. The values are a = 5, b=3 and d=1.5 f=a+b/a; c=d*a+b; c=a++ * d +a; f=++b * b – a; c=a-(b++) * (--d);
  • 16. Do you have any QUESTIONS ?

Editor's Notes

  • #2: 1 1 The “operator” keyword Overloading Unary operators Overloading Binary operators Constructors as conversion routines Converting between basic and user-defined types LEAD IN: Overloaded Unary Operators