Difference between char* and char[]

前端 未结 7 1251
清歌不尽
清歌不尽 2020-11-27 03:32

I know this is a very basic question. I am confused as to why and how are the following different.

char str[] = \"Test\";
char *str = \"Test\";
7条回答
  •  囚心锁ツ
    2020-11-27 03:48

    The first

    char str[] = "Test";
    

    is an array of five characters, initialized with the value "Test" plus the null terminator '\0'.

    The second

    char *str = "Test";
    

    is a pointer to the memory location of the literal string "Test".

提交回复
热议问题