Null character

Jun 5, 2013 at 4:25pm
Character strings in C++ are automatically terminated by null character. Explain how this feature helps in string manipulations.
Jun 5, 2013 at 4:31pm
We aren't here to do your homework for you.
Jun 5, 2013 at 5:06pm
Its not my homework. I am way past getting homework stage
Jun 5, 2013 at 5:10pm
Then you shouldn't be asking this question.
Jun 5, 2013 at 5:22pm
This feature allows to determine the actual size of a string.
Jun 5, 2013 at 6:03pm
It doesn't help, C++ strings would be manipulated just fine without that extra character. It helps the code that expects a C string to work, given a pointer to a character in a C++ string.
Jun 5, 2013 at 6:10pm
@Cubbi
The original post starts with "Character strings in C++..." Character strings and C++ class std::string are different things IMO.
Jun 6, 2013 at 10:42am
Its not my homework. I am way past getting homework stage

Really? Because it's worded exactly like a question in a homework assignment, or an exam, or a test.
Jun 6, 2013 at 10:56am
What 'manipulations' you talking about?
Jun 6, 2013 at 11:52am
@SameerThigale - Are you asking Cubbi? Please use @Cubbi if you're not responding to the OP.

As Cubbi implied, std::string keeps track of of how long a string is, so the trailing null character is not required. Any operation on (manipulation of) std::string objects implicitly knows how long each string object is. This is not true of C character strings.


Jun 6, 2013 at 12:44pm
I am mostly pointing out the ambiguity in the question: both C++ strings and string literals are "automatically terminated by null character", and both hold strings of characters.
Topic archived. No new replies allowed.