how is the precedence and associativity?

#define multiply(x) x*x

main()
{
int result;
result = multiply(2) + 1;
}

what is the result value?
i told the answer is 5 since the macro gets expanded as 2*2+1
and here the multiplication takes first and addition latter.
but the interviewer said ans is 6 since the evaluation takes place from Left to right so first addition and then multiplcation.
i am not sure now what is correct ? i think * and + have L to R associativity and * has higher precedence.
So, Friends....Can someone correct me if i am wrong?

No comments:

Post a Comment