SlideShare ist ein Scribd-Unternehmen logo
1 von 7
What is difference between Prefix & Postfix
(++i ,--i & i++ , i--)
So what is the difference????
Prefix Postfix
The ++ or -- symbol is
used before the variable.
The ++ or -- symbol is used
after the variable.
Example: ++i or --i Exmple i++ or i--
It means : i= i+1 or It means: i= i+1 or
i= i-1 i= i-1
It will be easy for u to understand these if u keep two things in
ur mind. That is :
In prefix : First increment / decrement by 1 then assign .
In postfix: First assign then increment/ decrement by 1 .
In prefix:
int i =5;
++i;
Output: 6
It works like:
i = ++i ; // First increment
= i+1;
= 5+1;
= 6;
int i = 6; // Then assign
Note:
In program the last & final value is accepted.
In postfix:
int i =5;
i++;
Output: 6
It works like:
int i = 5; // First assign
i =i++; // Then increment
= i+1;
= 5+1;
=6;
Note:
In program the last & final value is accepted.
**In prefix : First increment / decrement then assign**
If i and j are two variables then :
int i, j ;
i=9;
j=++i;
Output: i & j is : 10 10
Here, Compiler first add 1 to the initial value i=9. Then it
use the new incremented value in the same statement.
**In prefix : First assign then increment / decrement **
If i and j are two variables then :
int i, j ;
i=9;
j=i++;
Output: i & j is : 10 9
Try it yourself:
- -i & i- -
Hint: i = i -1;

Weitere ähnliche Inhalte

Andere mochten auch

PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...
PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...
PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...Dalia Violeta Gutierrez Ruíz
 
Songwriting Unleashed
Songwriting UnleashedSongwriting Unleashed
Songwriting UnleashedDaniel Mayo
 
А.Кумаков Apiship eRetailForum2015
А.Кумаков Apiship eRetailForum2015А.Кумаков Apiship eRetailForum2015
А.Кумаков Apiship eRetailForum2015InSales
 
História em quadrinhos
História em quadrinhosHistória em quadrinhos
História em quadrinhosSérgio Lima
 
Сколько стоит доступ в память, и что с этим делать
Сколько стоит доступ в память, и что с этим делатьСколько стоит доступ в память, и что с этим делать
Сколько стоит доступ в память, и что с этим делатьQrator Labs
 
DDoS Attacks - Scenery, Evolution and Mitigation
DDoS Attacks - Scenery, Evolution and MitigationDDoS Attacks - Scenery, Evolution and Mitigation
DDoS Attacks - Scenery, Evolution and MitigationWilson Rogerio Lopes
 
DDoS Prevention: Market Growth, Deployments, and NSS Test Results
DDoS Prevention: Market Growth, Deployments, and NSS Test ResultsDDoS Prevention: Market Growth, Deployments, and NSS Test Results
DDoS Prevention: Market Growth, Deployments, and NSS Test ResultsNSS Labs
 
Utilizando a Lousa Digital e o Projetor PROINFO
Utilizando a Lousa Digital e o Projetor PROINFOUtilizando a Lousa Digital e o Projetor PROINFO
Utilizando a Lousa Digital e o Projetor PROINFOSérgio Lima
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingPTtp WgWt
 
Latest resume ETA Aug 2016
Latest resume ETA Aug 2016Latest resume ETA Aug 2016
Latest resume ETA Aug 2016senthil kumar
 

Andere mochten auch (13)

PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...
PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...
PROYECTO ESTADISTICA "FACTORES QUE INFLUYEN QUE LOS ESTUDIANTES DEL PL18 TEHU...
 
Songwriting Unleashed
Songwriting UnleashedSongwriting Unleashed
Songwriting Unleashed
 
А.Кумаков Apiship eRetailForum2015
А.Кумаков Apiship eRetailForum2015А.Кумаков Apiship eRetailForum2015
А.Кумаков Apiship eRetailForum2015
 
História em quadrinhos
História em quadrinhosHistória em quadrinhos
História em quadrinhos
 
Виртуальный номер связывает филиалы в единую сеть
Виртуальный номер связывает филиалы в единую сетьВиртуальный номер связывает филиалы в единую сеть
Виртуальный номер связывает филиалы в единую сеть
 
Сколько стоит доступ в память, и что с этим делать
Сколько стоит доступ в память, и что с этим делатьСколько стоит доступ в память, и что с этим делать
Сколько стоит доступ в память, и что с этим делать
 
Capital budgeting
Capital budgetingCapital budgeting
Capital budgeting
 
DDoS Attacks - Scenery, Evolution and Mitigation
DDoS Attacks - Scenery, Evolution and MitigationDDoS Attacks - Scenery, Evolution and Mitigation
DDoS Attacks - Scenery, Evolution and Mitigation
 
WSO2-WSF-install-manual-linux-th
WSO2-WSF-install-manual-linux-thWSO2-WSF-install-manual-linux-th
WSO2-WSF-install-manual-linux-th
 
DDoS Prevention: Market Growth, Deployments, and NSS Test Results
DDoS Prevention: Market Growth, Deployments, and NSS Test ResultsDDoS Prevention: Market Growth, Deployments, and NSS Test Results
DDoS Prevention: Market Growth, Deployments, and NSS Test Results
 
Utilizando a Lousa Digital e o Projetor PROINFO
Utilizando a Lousa Digital e o Projetor PROINFOUtilizando a Lousa Digital e o Projetor PROINFO
Utilizando a Lousa Digital e o Projetor PROINFO
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Latest resume ETA Aug 2016
Latest resume ETA Aug 2016Latest resume ETA Aug 2016
Latest resume ETA Aug 2016
 

Kürzlich hochgeladen

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 

Kürzlich hochgeladen (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

Difference between Prefix & Postfix

  • 1. What is difference between Prefix & Postfix (++i ,--i & i++ , i--)
  • 2. So what is the difference???? Prefix Postfix The ++ or -- symbol is used before the variable. The ++ or -- symbol is used after the variable. Example: ++i or --i Exmple i++ or i-- It means : i= i+1 or It means: i= i+1 or i= i-1 i= i-1
  • 3. It will be easy for u to understand these if u keep two things in ur mind. That is : In prefix : First increment / decrement by 1 then assign . In postfix: First assign then increment/ decrement by 1 .
  • 4. In prefix: int i =5; ++i; Output: 6 It works like: i = ++i ; // First increment = i+1; = 5+1; = 6; int i = 6; // Then assign Note: In program the last & final value is accepted. In postfix: int i =5; i++; Output: 6 It works like: int i = 5; // First assign i =i++; // Then increment = i+1; = 5+1; =6; Note: In program the last & final value is accepted.
  • 5. **In prefix : First increment / decrement then assign** If i and j are two variables then : int i, j ; i=9; j=++i; Output: i & j is : 10 10 Here, Compiler first add 1 to the initial value i=9. Then it use the new incremented value in the same statement.
  • 6. **In prefix : First assign then increment / decrement ** If i and j are two variables then : int i, j ; i=9; j=i++; Output: i & j is : 10 9
  • 7. Try it yourself: - -i & i- - Hint: i = i -1;