2016-09-22 83 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? –