What is the difference between char a[] = ?string?; and char *p = ?string?;?

前端 未结 8 1013
太阳男子
太阳男子 2020-11-22 07:43

As the heading says, What is the difference between

char a[] = ?string?; and 
char *p = ?string?;  

This question was asked to me in inter

8条回答
  •  渐次进展
    2020-11-22 08:19

    char a[] = "string";
    

    This allocates the string on the stack.

    char *p = "string";
    

    This creates a pointer on the stack that points to the literal in the data segment of the process.

    ? is whoever wrote it not knowing what they were doing.

提交回复
热议问题