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 in Others by Rahul
• 8,980 points
30 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 by Aditya
• 7,280 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
716 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,060 points
354 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
9,093 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,280 points
310 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
232 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,060 points
473 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,060 points
261 views
0 votes
1 answer

Avoiding multiple nested for-loops in python

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

answered Sep 10, 2018 in Python by Priyaj
• 58,060 points
2,287 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 in Others by Aditya
• 7,280 points
17 views
0 votes
1 answer

Difference between margin and padding?

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

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