繁体   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