Possible Duplicate:
What's the rationale for null terminated strings?
My question is very simple: why do C++ strings end in null terminators? Is this so that you do not need to keep count on the length?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Traditional strings in C and C++ use a null terminator to indicate the end of the string. Since string pointers simply pointed to an array of characters, without any length or other meta data, the null terminator was the only way to determine the length of the string.
As far as why it was done this way, that’s more difficult question to answer. There are many ways to store string data, that’s just one of them.