首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(const char*)++或(const char)++?

(const char*)++或(const char)++?
EN

Stack Overflow用户
提问于 2013-12-20 10:51:33
回答 2查看 150关注 0票数 0
代码语言:javascript
复制
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    char *str = "hello";

    while (*str) {
        cout << *str;
        *str++;
    }

    return 0;
}

代码语言:javascript
复制
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    char *str = "hello";

    while (*str) {
        cout << *str;
        str++;
    }

    return 0;
}

双输出

代码语言:javascript
复制
hello

为什么在str++更改输出之前不添加或删除deference操作符?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-20 10:54:17

*str++的意思是*(str++)

由于您不使用该表达式的值,所以*没有任何效果。

票数 5
EN

Stack Overflow用户

发布于 2013-12-20 10:53:59

后缀++比去重引用操作符*具有更高的优先级,因此

代码语言:javascript
复制
*x++;

是相同的

代码语言:javascript
复制
*(x++);

它的作用与

代码语言:javascript
复制
x++;
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20701952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档