为什么9和49输出? 9是正确的,但为什么k = 49? [英] Why 9 and 49 output ? 9 is correct but why k=49 ?
本文介绍了为什么9和49输出? 9是正确的,但为什么k = 49?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <stdio.h>
#define PRODUCT(x) ((x)*(x))
int main()
{
int i=3,j,k;
j=PRODUCT(i++);
k=PRODUCT(++i);
printf("%d %d",j,k);
return 0;
}
推荐答案
我们可以逐步完成此代码:
int i = 3,j,k;
声明变量,i的值为3.
j = PRODUCT(i ++);
调用宏PRODUCT,i的值为3, 3 * 3 = 9.
现在此后因为(x)*(x),i的值将增加两次 !
i的值现在是5.
k = PRODUCT(++ i);
调用宏PRODUCT但之前因为(x)*(x)而i的值将增加两次是7和7 * 7 = 49。
We can go through this code step-by-step:
int i=3,j,k;
The variables are declared, the "i" has value of 3.
j=PRODUCT(i++);
The macro PRODUCT is called, the value of "i" is first 3 and 3*3 = 9.
Now after this the value of "i" will be incremented twice because of (x)*(x)!
The value of "i" is now 5.
k=PRODUCT(++i);
The macro PRODUCT is called but before the value of "i" will be incremented twice because of (x)*(x) and is 7 and 7*7 = 49.
这篇关于为什么9和49输出? 9是正确的,但为什么k = 49?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文