What does the "++" operator do on a "char *"?

c, char, operators, pointers

Solution

The `++` operator in `*str++` increments the pointer (not the thing pointed at).

(*str)++;   /* Increment the character pointed at by str */
 *str++;    /* Increment the pointer in str */
*(str++);   /* Increment the pointer in str - the same, but verbose */

There are two very different operations shown (one of them shown using two different but equivalent notations), though they both return the character that `str` pointed at before the increment occurs. This is a consequence of the precedence rules in the standard — postfix operators like `++` have higher precedence than unary (prefix) operators like `*` unless parentheses are used to alter this.

Problem

In the following function: ``` double dict(const char *str1, const char *str2) { ``` There is the following: ``` if (strlen(str1) != 0 && strlen(str2) != 0) while (prefix_length < 3 && equal(*str1++, *str2++)) prefix_length++; ``` What does the operator `++` do in `*str1++` and `*str2++`?

Original source