#include <iostream>
#include <cstring>
using namespace std;
int main() {
char *str = "hello";
while (*str) {
cout << *str;
*str++;
}
return 0;
}
和
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char *str = "hello";
while (*str) {
cout << *str;
str++;
}
return 0;
}
两个输出
hello
为什么在str++
更改输出之前添加或删除尊重运算符?
后
缀++
的优先级高于取消引用运算符*
,因此
*x++;
与
*(x++);
这真的与
x++;
>*str++
表示*(str++)
。
由于不使用该表达式的值,因此*
不起作用。