簡體   English   中英

(const char *)++還是(const char)++?

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM