Written in C and C-like languages (like C++ and Perl) as a prefixed "++": ++x. An expression which increments x as a side effect, and has its new value. So in C, it is exactly equivalent to the more verbose (x += 1).

You can use this to push an element onto the end of an array, if you're using an index to the last element; however, it's cleaner to store the number of elements, and use postincrement (see the example in that node).

Generally used when reading some array. For example, to chop off the remainder of a string after some character, you could write:

  void chop(char *s, char c)
    while (*s && *++s != c)
    *s = 0;
In C++, preincrement is generally prefered to postincrement (especially on an object), since it usually avoids a call to the copy constructor.

Log in or register to write something here or to contact authors.