为什么输出是9和19 [英] Why the output is 9 and 19

查看:86
本文介绍了为什么输出是9和19的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

include<stdio.h>

int main()
{
    int x=10;
    int a=1,b=2,c=3,d=4;
    x+=a=b*c+d-a;
    printf("%d,%d",a,x);
}

推荐答案

看来你正在学习C / C ++ - 很好,但我建议你先阅读一些基础知识有关它的书籍,所以你不需要询问有关运算符优先级的问题...

It seems you are into learning C/C++ - good, but I would advise you to read some basic books about it so you will not need asking questions about operator precedence...
x+=a=b*c+d-a



根据执行流程和运算符优先级将它分开,你将得到:


By breaking it apart according the execution flow and operator precedence, you will have this:

a=b*c+d-a = > a=((b*c)+d)-a;
x+=a => x=x+a;



从此处必须清楚...

C ++运算符优先级 - cppreference.com [ ^ ]


你有



As you have

int x=10;
   int a=1,b=2,c=3,d=4;
   x+=a=b*c+d-a;
   printf("%d,%d",a,x);







看看你的输出是怎样的,



x + = a& a = b * c + d-a



a = 2 * 3 + 4-1,结果为9

& x + = a表示x = x + a => 10 + 9 = 19




see how your output come,

x+=a & a=b*c+d-a

a= 2*3+4-1 which results as 9
& x+=a means x = x+a => 10+9= 19


这篇关于为什么输出是9和19的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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