#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++;
关于c++ - (const char*)++ 还是 (const char)++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20701952/