0
char* in C/C++
1. How does a pointer to a char can store a string that consists of multiple chars? 2. How does it know the length of the word? because it only knows the location of the first char of the string, but how does it know where does it end? Thanks.
1 Answer
+ 6
1. It doesn't, it just points to the first char of the string (char array)
2. It doesn't know the lenght and it doesn't know where it ends, but it knows how it ends
A strings is a null-terminated array of chars, that means that at the end of every string there is a '\0', that's how it knows when to stop
e.g.: "Hello" = ['H', 'e', 'l', 'l', 'o', '\0']