Q:

(3* - *p/(*q)+7) = 6 how it works?

int i=3,j=5;
    int *p, *q;
    p = &i;
    q = &j;

    printf("%d\n", 3* -*p/(*q)+7);

The compiler says the result is 6, but i can't understand how, for me it was suposed to be (-9/12) = -0,74 or 0 beacause is a int, can anyone help?

A:

Taking into account the precedence rules that are implicitly encoded in the grammar of the C language, 3* -*p/(*q)+7 is ((3 * (-*p)) / (*q)) + 7.
The result of -9 / 5 is -1 because / represents integer division here.
The result of -1 + 7 is 6.

A:

Because of operator precedence and associativity
3* -*p/(*q)+7 is the same as
(3 * - 3)/5 + 7 which is the same as
-9/5 + 7 which because of integer division is the same as
-1 + 7 which is the same as   
6

