2016-09-22 84 views
-2
#include<stdio.h> 
#include<conio.h> 
#define FIRST_PART 7 
#define LAST_PART 5 
#define ALL_PARTS FIRST_PART+LAST_PART 
int main() 
{ 
    printf ("The Square root of all parts is %d", ALL_PARTS * ALL_PARTS) ; 
    getch(); 
    return(0); 
} 

在上面的代碼中FIRST_PART被定義爲7輸出47是怎樣的?

LAST_PART被定義爲5

和ALL_PARTS被初始化爲FIRST_PART + LAST_PART(其理想地12)

但是當我打印ALL_PARTS * ALL_PARTS是給我47作爲輸出!(但我認爲答案將是144)

請任何人都可以解釋我怎麼做?

+0

7 + 5×7 + 5是47,那麼你爲什麼不期待的答案嗎? (提示:如果作爲宏的一部分進行計算,用括號包住) –

+0

它應該是47 – iamsankalp89

回答

1

答案應該是47

FIRST_PART + LAST_PART * FIRST_PART + LAST_PART 

MULTIPLICATION HAS MORE PRECEDENCE 

SO 7 + 5 * 7 + 5 

7 + 35 + 5 

47 
+1

希望它能幫助你 –

+0

但值5 + 7 = 12,對不對? –

+0

ALL_PARTS的值應該是12 * 12? –