增量和减量printf中的变量 [英] increment and decrement of a variable in printf

查看:80
本文介绍了增量和减量printf中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的程序,其中 int类型的= 10 的O / P,我期待为 10 9 9

I wrote a simple program where int a = 10 the o/p which i was expecting was 10 9 9

 printf("a++:%d \t a:%d \t --a: %d \n", a++, a, --a); 

但它得到了O / P是 9 10 10

我写了另一个类似的printf 的printf(一个数:%d \\ t --a数:%d \\ n,一,--a);

I wrote another printf like printf(" a:%d \t --a: %d \n", a, --a);

在O / P,我得到的是 10 10

the o/p which i got is 9 9

任何人都可以解释我这个?

can anyone explain me about this ?

推荐答案

您遇到的未定义行为的,通过与副作用多前pressions,没有的序列点插图中

You're experiencing undefined behavior, by having multiple expressions with side-effects, without sequence points inbetween.

有没有保证的次序函数参数进行评估,所以没有办法期望的东西在这里(除非你写的编译器)。

There's no guarantee in which order function arguments are evaluated, so there's no way to "expect" something here (unless you wrote the compiler).

这篇关于增量和减量printf中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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