(const char *)++或(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++更改输出之前不添加或删除引用运算符

史蒂夫·杰索普

*str++意味着*(str++)

由于您不使用该表达式的值,因此*无效。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章