为什么的sizeof(X ++),不增加x? [英] Why does sizeof(x++) not increment x?

查看:704
本文介绍了为什么的sizeof(X ++),不增加x?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是code在开发的C ++编译窗口:

Here is the code compiled in dev c++ windows:

#include <stdio.h>

int main() {
    int x = 5;
    printf("%d and ", sizeof(x++)); // note 1
    printf("%d\n", x); // note 2
    return 0;
}

我期待 X 执行注意后为6 1 即可。然而,输出的是:

I expect x to be 6 after executing note 1. However, the output is:

4 and 5

任何人都可以解释为什么 X 注意不增加1

推荐答案

从的 C99标准(重点是我的)

6.5.3.4/2

6.5.3.4/2

sizeof操作符得到其操作数的大小(以字节为单位),这可能是一个前pression或类型的括号名称。尺寸是从操作数的类型来确定。结果是整数。如果操作数的类型是可变长度数组类型,操作数被评估;否则,的操作数不计算,结果是整型常量。

The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant.

这篇关于为什么的sizeof(X ++),不增加x?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆