(const char*)++ or (const char)++?

(const char*)++ or (const char)++?

本文关键字:char const or      更新时间:2023-10-16
#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++;

>*str++表示*(str++)

由于不使用该表达式的值,因此*不起作用。