gpt4 book ai didi

c - C中的后增量概念

转载 作者:太空宇宙 更新时间:2023-11-04 03:38:01 25 4
gpt4 key购买 nike

输出和为什么?根据我的知识,在执行语句后进行增量评估。这里在左侧,逻辑“i”值是 1 还是 2?

#include <stdio.h>
int main()
{
int i = 1;
if (i++ && (i == 1))
printf("Yes\n");
else
printf("No\n");
}

最佳答案

Here On the left side if logical 'i' value will be 1 or 2?

它将是 2 因为有一个 sequence point在逻辑 && 的左右操作数的求值之间。

c-faq定义序列点为

A sequence point is a point in time at which the dust has settled and all side effects which have been seen so far are guaranteed to be complete.

这意味着在计算&&的右操作数之前,i的副作用已经保证完成。

关于c - C中的后增量概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30685668/

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