Search code examples
turbo-c

How is the output 47?


#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);
}

In the above code the FIRST_PART is defined as 7

LAST_PART is defined as 5

and ALL_PARTS is initialized as FIRST_PART+LAST_PART (which is ideally 12)

but when i am printing ALL_PARTS * ALL_PARTS is giving me 47 as the output!(But i thought answer would be 144)

Please can anyone explain me how ?


Solution

  • The answer should be 47

    FIRST_PART + LAST_PART * FIRST_PART + LAST_PART
    
    MULTIPLICATION HAS MORE PRECEDENCE
    
    SO 7 + 5 * 7 + 5
    
     7 + 35 + 5
    
    47