In this chapter we'll meet some (though still not all) of C's more advanced arithmetic operators. The ones we'll meet here have to do with making common patterns of operations easier.
It's extremely common in programming to have to increment a variable by 1, that is, to add 1 to it. (For example, if you're processing each element of an array, you'll typically write a loop with an index or pointer variable stepping through the elements of the array, and you'll increment the variable each time through the loop.) The classic way to increment a variable is with an assignment like
i = i + 1Such an assignment is perfectly common and acceptable, but it has a few slight problems:
a[i+j+2*k] = a[i+j+2*k] + 1is a bit of a mess, and you may have to look closely to see that the similar-looking expression
a[i+j+2*k] = a[i+j+2+k] + 1probably has a mistake in it.
7.2 Increment and Decrement Operators
Read sequentially: prev next up top
This page by Steve Summit // Copyright 1995-1997 // mail feedback