We want to go over each pair of elements in array once.
1 2 3 4 |
|
What is the correct expression for the inner loop?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
I have objections to all of the answers. The first objection that it should not be arr; but, A. The second objection is that it should be ++j and not j++. Yes, modern compilers optimize away the unnecessary save of the original value of j. Yes, the example of a for loop on page 57 of the first edition of The C Programming Language by K&R shows a preincrement. As Dr. Kernighan worked short distance away from me at Bell Labs, I asked him about the use of a preincrement in this case and he said it was a mistake not caught in proofreading.