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
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"
.