I do not understand the behaviour of #define macro in C++

后端 未结 4 1337
既然无缘
既然无缘 2021-01-29 14:09

I need to understand how this code works:

#define foo1( a ) (a * a)              // How does this work?
inline int foo2(         


        
4条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 14:42

    Well, it's really simple.

    foo1( 1 + 2 )
    

    will turn into:

    ( 1 + 2 * 1 + 2 )
    

    which is actually:

    1 + 2 + 2 = 5
    

    This is how macros work.

提交回复
热议问题