用C打印顺序 [英] Printing order in C

查看:110
本文介绍了用C打印顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int x=10;
printf("%d %d %d\n",x,++x,x++);
printf("%d %d %d",x,x+20,x+30);

在打印输出

12 12 10
12 32 42

为什么第一个printf的顺序是相反的顺序,为什么不能在第二printf语句?
我在C使用反向打印顺序一本书找到。

Why the order in first printf is in reverse order and why not in second printf statement? i found in a book that C uses reverse printing order.

推荐答案

您code的未定义行为(UB)。因此,任何事情都有可能发生。

Your code has undefined behavior ("UB"). Thus, anything can happen.

具体而言,违反了规则是不能读取和写入同一个变量没有序列点除了确定写入值。

Specifically, the rule violated is that must not read and write the same variable without sequence-point except to determine the value to write.

这篇关于用C打印顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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