DEV Community

Cover image for What are i++ or ++i or i-- or --i in programming language?? Why you should use them?
Md. Fahim Bin Amin
Md. Fahim Bin Amin

Posted on

What are i++ or ++i or i-- or --i in programming language?? Why you should use them?

In our programming learning, we frequently use the i++ or ++i, i-- or --i.

Sometimes, it is pretty tricky to understand why we use them and how they actually work in different perspective.

However, I have discussed everything in a video.

📹 Make sure to watch it to understand better.

Let me also clarify what we call those 4 specific things:

  • i++: Post increment
  • ++i: Pre increment
  • i--: Post decrement
  • --i: Pre decrement

You can connect me via:

🎁 LinkedIn, Twitter, GitHub, English YouTube Channel, Bengali YouTube Channel

🖼️ Cover: Photo by Nate Grant on Unsplash

Top comments (2)

Collapse
 
phlash profile image
Phil Ashby

Typo :) "--i: pre-increment" should probably say pre decrement.

It's interesting to note that some popular languages do not support these operators for safety reasons, notably: Python & Rust.

Personally I try to avoid these operators unless I need the result of the expression and it's an idiomatic form eg in C: *p++ = val; particularly in the third term of a for loop, where I prefer val += 1 which is more portable.

Collapse
 
fahimfba profile image
Md. Fahim Bin Amin

Thank you so much for the correction. I did a mistake there for having a rush! Silly me 😅

That's also true, but we tend to use that in Java, C/C++ a lot to be honest.