2011-03-31 95 views
0
#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=6x=1+4=5a=6-5=1t=8-4=4)...請告訴我如何y當屬6,我以爲y1+4=5a=1t=4

謝謝,請幫助我。

回答

1

由第一噸增加,然後一個和t之和返回

所以,叔爲4,則執行操作者T + = A和T變得5. 和A + T == 1+ 5 == 6返回

5

告訴我Ÿ是怎麼來的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 
} 
+0

謝謝!我忘了增加一個回報聲明,但現在它已被清除。 :) – John 2011-03-31 22:59:16

1

使用dok函數將t的值更改爲4,並且doky函數將該值增加1(a中的值)。總結該(5到目前爲止)到再次(設置爲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 = 6 
0

Y = A + T = A + T + A = 1 + 4 + 1 = 6 :)

0

只是用鉛筆和紙做...

 
       | t | x | y | s | a | 
-----------------+---+---+---+---+---+ 
before main  | 8 |#NA|#NA|#NA|#NA| 
before x=dok(s) | 8 | ? | ? | 6 |#NA| 
inside dok  | 4 |#NA|#NA|#NA| 1 | 
after dok  | 4 | 5 | ? | 6 |#NA| 
before y=doky(s) | 4 | 5 | ? | 6 |#NA| 
inside doky  | 5 |#NA|#NA|#NA| 1 | 
after doky  | 5 | 5 | 6 | 6 |#NA|