Search code examples
coperator-precedence

Precedence of * and / in C


I didnt get the logic behind the answer. I tried to print the value of a after definition and it shows a=72. Please help.

    #include<stdio.h>
    main()
    {
       int a=400*400/400;
       if(a==400)
       printf("Do good");
       else
       printf("Have good");
    }

output : Have Good


Solution

  • I guess that on your platform int is 2 byte wide, 16 bit.

    Then

    400*400 = 28928
    

    Due to overflow

    28928/400 = 72