The difference between n++ and ++n at the end of a while loop? (ANSI C)

The only difference between n++ and ++n is that n++ yields the original value of n, and ++n yields the value of n after it’s been incremented. Both have the side effect of modifying the value of n by incrementing it.

If the result is discarded, as it is in your code, there is no effective difference.

If your program is behaving differently depending on whether you write




it must be for some other reason.

In fact, when I compile and execute your program on my system, I get exactly the same output in both cases. Adding newlines to the output format, I get:

At n = 25, Algorithm A performs in 114661785600 seconds &
Algorithm B performs in 282429536481 seconds.

You haven’t told us what output you’re getting. Please update your question to show the output in both cases.

Leave a Comment