Square of a number being defined using #define

后端 未结 11 1202
说谎
说谎 2020-11-27 08:06

I was just going through certain code which are frequently asked in interviews. I came up with certain questions, if anyone can help me regarding this?

I am totally

11条回答
  •  臣服心动
    2020-11-27 08:42

    As the other answers say, you're getting burned by operator precedence. Change your square macro to this:

    #define square(x) (x*x)
    

    and it'll work the way you expect.

提交回复
热议问题