C #define macros

后端 未结 7 1328
情书的邮戳
情书的邮戳 2020-12-21 06:59

Here is what i have and I wonder how this works and what it actually does.

#define NUM 5
#define FTIMES(x)(x*5)

int main(void) {
    int j = 1;
    printf(\         


        
相关标签:
7条回答
  • 2020-12-21 07:25

    The compiler pre-process simply does a substitution of FTIMES wherever it sees it, and then compiles the code. So in reality, the code that the compiler sees is this:

    #define NUM 5
    #define FTIMES(x)(x*5)
    
    int main(void)
    {
    
        int j = 1;
    
        printf("%d %d\n", j+5*5,(j+5)*5);
    }
    

    Then, taking operator preference into account, you can see why you get 26 and 30.

    0 讨论(0)
提交回复
热议问题