c的增量和加法 [英] increement and addition in c

查看:129
本文介绍了c的增量和加法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
int main(int argc, char** argv)
{
   int x = 3;
   printf("%d ";, x++ + ++x);
   return 1;
}</stdio.h>


请,我需要知道为什么输出会是8,因为我认为必须是7?


Please, I need to know why the output will be 8 since I think it has to be 7?

推荐答案

感谢您对Mamun的回复
但我想问个问题
我知道x ++在printf期间不会递增3,但是在它之后并另存为x = 4,这就是加法运算,这意味着直到现在我们有了3+,然后才是++ x,首先是递增x,所以x现在将是5,因为它是4,并且增加了1
最后我们有3 + 5 = 8

这是你的意思吗
谢谢:)
thanks for ur reply Mamun
but i want to ask something
i know that x++ here won''t increment 3 during printf but after it and save as x=4 then comes the addition operation this means till now we have 3+ then comes the ++x and this increment x firstly so x now will be 5 beacause it was 4 and increased by 1
finally we have 3+5=8

is this what u mean
thanks :)


谢谢您的提问,

Than you for your question,

int x = 3; //now three
printf("%d ";, x++ + ++x); // in the line
x++ means 3 + 1 = 4
++x this statement will decrease 1 from 4 but after addition.
so, x++ + ++x will be 8. 



谢谢,
马蒙



Thanks,
Mamun


这篇关于c的增量和加法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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