What is the difference between Post and Pre increment? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between Post and Pre increment?

Sir I wrote this i = 1 i =+ 5 print(i) Output: 5 Doubt: sir it should show 6 ryt? Also when I tried += then it showed me 6. So, which one is correct sir? I AM CONFUSED THAT HOW THESE TWO ARE DIFFERENT.... :( Also the names I got from google (that post and pre increment) So clarify please sir :(

1st Oct 2020, 8:57 AM
Amresh
Amresh - avatar
2 Answers
0
Hi! In your example this is no post or pre increment. See this: ++x - pre, x++ - post
2nd May 2021, 3:25 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
When we increase the value of a variable before assigning it to another variable then it is known as Pre-Increment. When the value of a variable is incremented after assigning it to a variable, it is known as Post-Increment. See: https://bitdifference.com/post-vs-pre/
28th Feb 2023, 6:34 PM
harley8527