C编程中的操作员 [英] Operators in C programming

查看:78
本文介绍了C编程中的操作员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
main()
{
	int i=2;
	printf("\n%d %d",++i,++i);
	getch();

}



这里我在turboC上工作,我得到输出4,3

请解释原因



我尝试了什么:



但据我所知

++我所以我增加并打印

所以我认为输出必须是3,4


here i do on turboC and i getting output 4,3
please explain why

What I have tried:

but according to me
++i so i incremented and printed
so i think that it must be 3,4 to be output

推荐答案

阅读以下内容:

c - 解释评估顺序在printf - Stack Overflow [ ^ ]



在C中调用函数之前的参数评估顺序 - Stack Overflow [ ^ ]
Read the following:
c - Explain the order of evalution in printf - Stack Overflow[^]

Parameter evaluation order before a function calling in C - Stack Overflow[^]


您处于灰色区域,生成的代码是编译器选择,因此无法预测。

唯一的建议是:永远不要在单行代码中在同一个变量上写入超过1个增量的代码。

此代码:

You are in a gray zone, the resulting code is the compiler choice and thus it is unpredictable.
The only advice is: never write code with more than 1 increment on same variable in single line of code.
This code:
#include<stdio.h>
main()
{
	int i=2;
	printf("\n%d %d",++i,++i);
	getch();
}



可以转换为:


can translate to:

#include<stdio.h>
main()
{
	int i=2;
	int t1=++i;
	int t2=++i;
	printf("\n%d %d",t1,t2);
	getch();
}



或者:

可以转换为:


or to:
can translate to:

#include<stdio.h>
main()
{
	int i=2;
	int t1=++i;
	int t2=++i;
	printf("\n%d %d",t2,t1);
	getch();
}



这只是编译器的选择。


It is only compiler choice.


这篇关于C编程中的操作员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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