What does #x inside a C macro mean?

前端 未结 4 1821
死守一世寂寞
死守一世寂寞 2020-11-27 03:03

For example I have a macro:

#define PRINT(int) printf(#int \"%d\\n\",int)

I kinda know what is the result. But how come #int repersent the

4条回答
  •  情歌与酒
    2020-11-27 03:53

    That is a bad choice of name for the macro parameter, but harmless (thanks dreamlax).

    Basically if i write like so

    PRINT(5);
    

    It will be replaced as

    printf("5" "%d\n",5);
    

    or

    printf("5 %d\n",5);
    

    It is a process called Stringification, #int is replaced with a string consisting of its content, 5 -> "5"

提交回复
热议问题