gpt4 book ai didi

c - C编译器如何解释以下代码序列

转载 作者:行者123 更新时间:2023-11-30 20:55:22 25 4
gpt4 key购买 nike

我有这个 C 代码行:

int a;
a = (1, 2, 3);

printf("%d", a);

为什么值 3被打印? (最后一个)。

最佳答案

逗号运算符计算其所有“成员”,但返回最后一个表达式的值。
来自 C11 标准:

The left operand of a comma operator is evaluated as a void expression; there is a sequence point between its evaluation and that of the right operand. Then the right operand is evaluated; the result has its type and value.

关于c - C编译器如何解释以下代码序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33527832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com