关于C代码的问题 [英] Question about c code

查看:53
本文介绍了关于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();




代码的输出是7和12


我不明白此输出如何产生,请帮助我




THE OUTPUT OF CODE IS 7 AND 12


i not understand how this output comes plz help me

推荐答案

1)x = 2,y = 3
2)x = 3 + 2-> x ++,y ++-> x = 6 y = 4
3)y =(y + 1)+(x + 1)-> x = 7,y = 12
1) x=2, y=3
2) x = 3 + 2 -> x++ , y++ -> x=6 y=4
3) y = (y+1) + (x+1) -> x= 7 , y = 12


x=y++ + x++;



在这行代码中,您得到了x =(3)+(2)= 5
现在发布增量将完成
所以x ++给出(5 + 1)= 6
y ++给出(3 + 1)= 4



With this line u got x=(3)+(2)=5
now post increment will done
so x++ gives (5+1)=6
y++ gives (3+1)=4

y=++y + ++x;



从这一行中,您得到y = 12,即
预增量将在执行表达式之前完成.
所以现在x = 7,y = 5
y =(5)+(7)= 12



From this line you got y=12 i.e
pre increment will be done before execution of expression.
so now x=7,y=5
y=(5)+(7)=12


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

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