这项计划的目标是什么? [英] what is the out put for this program

查看:62
本文介绍了这项计划的目标是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   stdio.h  >  
main()
{
int i = 2 ;
printf( %d%d%d%d%d i,i ++, ++ I I, - , - I);
}

请解释输出

解决方案

看看:

http://www.c4learn.com/increment-operator-in-c-programming.html [<一个href =http://www.c4learn.com/increment-operator-in-c-programming.htmltarget =_ blanktitle =新窗口> ^ ]

http://www.learncpp.com/cpp-tutorial/33- incrementdecrement-operators-and-side-effects / [ ^ ]

http:// www .tutorialspoint.com / cplusplus / cpp_increment_decrement_operators.htm [ ^ ]





http://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i [ ^ ]

http://stackoverflow.com / questions / 484462 / i-and-i-in-a-loop中的差异 [ ^ ]


实际上编译器从右向左移动所以最正确的表达式是 - -一世;它意味着它首先将i的值从2更改为1并打印1然后i--它表示i的第一个打印值,即i然后将i的值减小为0然后++ i首先将i的值增加到1然后打印1和下一个是i ++它的第一个打印值i即1并且增加值并且最后i的值是2因此它打印2并且打印顺序是从左到右所以它打印2 1 1 1 1. / BLOCKQUOTE>

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

please explain output

解决方案

Have a look:
http://www.c4learn.com/increment-operator-in-c-programming.html[^]
http://www.learncpp.com/cpp-tutorial/33-incrementdecrement-operators-and-side-effects/[^]
http://www.tutorialspoint.com/cplusplus/cpp_increment_decrement_operators.htm[^]


http://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i[^]
http://stackoverflow.com/questions/484462/difference-between-i-and-i-in-a-loop[^]


actually compiler go from right to left so right most expression is --i; it means it first change value of i from 2 to 1 and print 1 then i-- it means first print value of i i.e. 1 and then decrease the value of i to 0 then ++i first increases the value of i to 1 then print 1 and next one is i++ it first print value of i i.e. 1 and the increase the value and at last value of i is 2 so it print it 2 and print order is left to right so it prints 2 1 1 1 1.


这篇关于这项计划的目标是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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