[英](const char*)++ or (const char)++?
#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++
更改输出之前不添加或删除deference运算符?
Postfix ++
优先级高于反引用运算符*
,因此
*x++;
是相同的
*(x++);
确实与
x++;
*str++
表示*(str++)
。
由于您不使用该表达式的值,因此*
无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.