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

前端 未结 8 701

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:35

    A string literal is stored in memory as a character array. You identify an array with its starting address in C. However you cannot do

    int * ip = 5;
    

    Buy you can do (edited:)

    int ip[] = {5, 6, 4};
    

    for example.

提交回复
热议问题