What is a null-terminated string?

A null-terminated string is a contiguous sequence of characters, the last one of which has the binary bit pattern all zeros. I’m not sure what you mean by a “usual string”, but if you mean std::string, then a std::string is not required (until C++11) to be contiguous, and is not required to have a terminator. Also, a std::string‘s string … Read more

How to memset char array with null terminating character?

Options one and two are just wrong. The first one uses the size of a pointer instead of the size of the array, so it probably won’t write to the whole array. The second uses sizeof(char*) instead of sizeof(char) so it will write past the end of the array. Option 3 is okay. You could also use this but sizeof(char) is … Read more