Using macro results in incorrect output when used as part of a larger math expression - why does this happen?

前端 未结 13 2106
别那么骄傲
别那么骄傲 2020-12-11 17:50

This is a normal C routine program which i found out in some question bank. It is shown below:

#define CUBE(p) p*p*p

main()
{
    int k;
    k = 27 / CUBE(3         


        
13条回答
  •  眼角桃花
    2020-12-11 18:37

    Hi answer for this is:81 Explanation: In step k=27/cube(3) cube(3) is replaced by 3*3*3 by preprocessor.then above statement becomes as k=27/3*3*3 in that 27/3 expression is evaluated by c compiler(operator precedence) the result is(27/3) :9 the statement k=27/3*3*3 becomes as k=9*3*3; the result for above statement is 81:

提交回复
热议问题