再问一个关于C的问题 [英] Again Question about C

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

问题描述

#include <stdio.h>
#include <conio.h>
void main()
{

int x=2,y=3;
x=++y + ++x;
y=++y + ++x;
printf("%d%d",x,y);
getch();




}




代码的输出是8和13



我希望这是怎么实现的,请帮助我




The output of code is 8 and 13



i want how this comes plz help i

推荐答案

首先研究增量前和增量后运算符,然后您将确切知道发生了什么.

预增量将在执行语句之前完成
和后递增将在执行语句后执行

所以
您的结果将如下所示.

First study about the pre-increment and post-increment operators then you will know exactly what happening.

pre-increment will be done before execution of statement
and post-increment will be done after execution of statement

so
your result will be as below.

x=++y + ++x;


在这里

 ++y=4,++x=3
x=4+3=7 





y=++y + ++x;



从上面的声明中



from above statement

++y=4+1=5
++x=7+1=8
y=5+8=13


所以最后x = 8和y = 13


so finally x=8 and y=13


x=++y + ++x;


表示


means

x=(1+3)+(1+2)=7 ,y=4


y=++y + ++x;


表示


means

y=(1+4)+(1+7)=13


遵循上一个问题中给出的指导原则,您可以弄清楚这一点.
Follow the guideline given in your last question and you can figure this out.


这篇关于再问一个关于C的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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