[英](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.