Why must int pointer be tied to variable but not char pointer?

前端 未结 8 684

I am not sure if I worded the question correctly, but here it is spelled out:

char * cp = \"this is a char pointer\";

The code above, based

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 10:20

    In C, strings are pointers to null-terminated sequences of characters. That's why:

    char * cp = "this is a char pointer";
    

    is accepted. On the other hand, if:

    int * ip = 5;
    

    were accepted (you can force it if you insist), it would declare "ip is a pointer to an int, whose address is 5").

提交回复
热议问题