#include<stdio.h>
#include<conio.h>
int t=8;
int dok(int);
int doky(int);
int main()
{
int clrscr();
int x,y;
int s=2;
s*=3;
x=dok(s);
y=doky(s);
printf("%d%d%d",s,y,x);
getch();
return 0;
}
int dok(int a)
{
a+=-5;
t-=4;
return(a+t);
}
int doky(int a)
{
a=1;
t+=a;
return(a+t);
}上述代码的答案: 665
我理解为什么s=6,x=1+4=5 (a=6-5=1,t=8-4=4)...请告诉我y是怎么变成6的,我还以为y是1+4=5 (a=1,t=4)
谢谢,请帮帮我。
发布于 2011-04-01 06:55:49
告诉我y是怎么变成6...
调用dok函数会将t修改为4。
int doky(int a)
{
a=1;
t+=a; // Previously t is 4 because of t-=4 in earlier function call
// t = 4+1 = 5
return(a+t); // 1+5 = 6 retured
}发布于 2011-04-01 06:55:40
首先t增加a,然后返回a和t的和
因此,t是4。然后执行运算符t += a,t变成5。然后返回a+t == 1+5 == 6
发布于 2011-04-01 06:59:22
使用dok函数将t的值更改为4,并且doky函数将该值递增1(a中的值)。将这个(到目前为止的5)与a的值相加(设置为1),结果是4+1+1 = 6。
//t is 4, the value of a is irrelevant since it changes on the next instruction.
a=1;
t+=a; // t is now 5
return(a+t); // 1+5 = 6https://stackoverflow.com/questions/5507310
复制相似问题