What is the difference between i and i

0 votes
In C, what is the difference between using ++i and i++, and which should be used in the incrementation block of a for loop?
Feb 17, 2022 in Others by Rahul
• 9,680 points
758 views

1 answer to this question.

0 votes

To answer your question, the ++i will increment the value of i, and then return the incremented value.
i = 1; j = ++i; (i is 2, j is 2) whereas, the i++ will increment the value of i, but return the original value that i held before being incremented.
i = 1; j = i++; (i is 2, j is 1)

For a for loop, either works. ++i seems more common. However, in any case, follow the guideline "prefer ++i over i++" and you won't go wrong.

You can verify this by looking at the generated code, which will be identical.

answered Feb 17, 2022 by Aditya
• 7,680 points

Related Questions In Others

0 votes
1 answer

What is the difference between hadoop and google analytics ?

I will try and answer this as ...READ MORE

answered Aug 22, 2018 in Others by Frankie
• 9,830 points
1,635 views
+1 vote
1 answer

What is the difference between Dark Web and Deep Web?

The content that which you cannot find ...READ MORE

answered Feb 6, 2019 in Others by Priyaj
• 58,020 points
1,206 views
0 votes
1 answer

What is the difference between BASH and DOS?

The major difference between the BASH and ...READ MORE

answered Mar 8, 2019 in Others by Nabarupa
17,024 views
0 votes
1 answer

What is the difference between loadash and underscore

Loadash makes iterating arrays, strings, and objects easy in ...READ MORE

answered Jun 21, 2019 in Others by sunshine
• 1,300 points
1,104 views
0 votes
0 answers

Difference between for loop and the range based loop in C++

The distinction between a for loop and ...READ MORE

Jul 11, 2022 in C++ by Nicholas
• 7,760 points
602 views
0 votes
1 answer

Working of post increment operator in Java

Well, I think the confusion is because ...READ MORE

answered May 23, 2018 in Java by geek.erkami
• 2,680 points
831 views
0 votes
1 answer

Python: nested 'for' loops

Could use itertools: >>> for comb in itertools.combinations_with_replacement(range(9, -1, ...READ MORE

answered Sep 3, 2018 in Python by Priyaj
• 58,020 points
1,026 views
0 votes
1 answer

Avoiding multiple nested for-loops in python

You can replace the three loops with: from ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,020 points
920 views
0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
727 views
0 votes
1 answer

Difference between margin and padding?

In simple words, padding as a term ...READ MORE

answered Feb 18, 2022 in Others by Aditya
• 7,680 points
509 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP