Is it possible to have a pointer literal?

前端 未结 3 1130
夕颜
夕颜 2020-12-10 14:37

In C one can have string literals in the form of

char *string = \"string here\";

integer literals:

uint8_t num = 5;
         


        
3条回答
  •  情歌与酒
    2020-12-10 15:22

    No, it's not. That is because literals are valid values, and the only valid pointers are addresses of objects, i.e. the result of address-of operations or of pointer arithmetic on valid pointers.

    You could argue that the nullptr keyword furnishes a kind of "pointer literal"; the C++ standard calls it that. It is however the only pointer literal, and ironically it is not of pointer type.

提交回复
热议问题