对包含前缀和后缀运算符的 printf() 感到困惑 [英] confused about printf() that contains prefix and postfix operators

查看:47
本文介绍了对包含前缀和后缀运算符的 printf() 感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 int var=20 那么如何

If int var=20 then how

printf("%d %d %d", var--, ++var, --var); 

执行发生在 C 编程语言中.

execution happens in C programming language.

推荐答案

这是未定义的行为,因为 var 被多次修改,中间没有序列点.例如,序列点可以是 ;.然而,参数列表中的逗号并没有引入序列点,操作数的计算顺序也是未定义的(你可以说,代码是双重未定义的......).

It is undefined behaviour because var is modified several times without a sequence point in between. A sequence point would be, for example, a ;. The commas in parameter lists, do, however, not introduce sequence points, also the order in which the operands are evaluated is undefined (you could say, the code is doubly undefined ...).

这篇关于对包含前缀和后缀运算符的 printf() 感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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