为什么" I"在我的程序变量递增得到两次? [英] Why is "i" variable getting incremented twice in my program?

查看:211
本文介绍了为什么" I"在我的程序变量递增得到两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个朋友给我看了这个节目,问我为什么 I 变量递增得到两次。

One of my friend showed me this program and asked me why is i variable getting incremented twice.

据我的了解 MAX(我+ +,++ j)条; 在这一行 I 是先发的一个参数,然后递增,因此,如果的初始值i 10 则增加后的值应 11 ,但它显示的增加值 I 12

According to my understanding MAX(i++, ++j); in this line i is first send as a parameter and then incremented, so if the initial value of i is 10 then the incremented value should be 11, but it shows the incremented value of i as 12.

程序:

#include<stdio.h>

#define MAX(x,y) (x)>(y)?(x):(y)

void main(void)
{
    int i = 10;
    int j = 5;
    int k = 0;

    k = MAX(i++, ++j);

    printf("%d %d %d",i,j,k);
}

输出:

12 6月11日

有人可以解释我的价值是如何增加到12?

Can someone please explain me how is the value incremented to 12 ?

感谢。

推荐答案

您宏替换意味着你写(我++)&GT;(++ J)(我+ +):(++ j)条

这篇关于为什么&QUOT; I&QUOT;在我的程序变量递增得到两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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