Take the 2-minute tour ×  In many code samples, people usually
use '\0' after creating a new char array like this:  string s =
"JustAString"; char* array = new char[s.size() + 1];
strncpy(array, s.c_str(), s.size()); array[s.size()] = '\0';
Why should we use '\0' here?  share|improve this question
cstrings aren't usually the best idea in c++ code –  Anthony
Sottile Jun 8 '12 at 4:23 C string, which is a essentially a
char array, must be NUL terminated. Otherwise, the functions in
string.h will not function as expected. –  nhahtdh Jun 8 '12 at
4:24 In C, you will see this a lot. In C++, there are probably
better ways to get the same thing accomplished. –  jedwards Jun
8 '12 at 4:24 It's a convention –  valdo Jun 8 '12 at 6:09 it is
not for the compiler, it is for the libraries and possibly your
code. C does not support arrays properly. You can have local
arrays, but there is no way to pass them about. If you try you
just pass the start address (address of first element). So you
can ever have the last element