String pointer and array of chars in c

后端 未结 5 2067
南方客
南方客 2021-02-06 02:19

I just start learning C and found some confusion about the string pointer and string(array of char). Can anyone help me to clear my head a bit?

// source code
ch         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 02:59

    Although pointer and array seems familiar, they are different. the char *name3 is just a pointer to char, it takes no more memory than a pointer. it just store a address in it, so you can assign a string to it then the address stored in name3 change to the address of "Apple".

    But your name4 is an array of char[10], it holds the memory of 10 chars, if you want to assign it, you need to use strcpy or something to write it's memory, but not assign it with an address like "Apple".

提交回复
热议问题