在下面的函数中:
double dict(const char *str1, const char *str2) {
有以下内容:
if (strlen(str1) != 0 && strlen(str2) != 0)
while (prefix_length < 3 && equal(*str1++, *str2++)) prefix_length++;
运算符++
在*str1++
和*str2++
中做了什么?
最佳答案
*str++
中的 ++
运算符递增指针(不是指向的东西)。
(*str)++; /* Increment the character pointed at by str */
*str++; /* Increment the pointer in str */
*(str++); /* Increment the pointer in str - the same, but verbose */
显示了两个截然不同的操作(其中一个使用两种不同但等效的符号显示),尽管它们都返回 str
在增量发生之前指向的字符。这是标准中优先规则的结果 — postfix operators像 ++
比 unary (prefix) operators 有更高的优先级像 *
除非使用括号来改变它。
关于c - "++"运算符在 "char *"上做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17714292/