Possible Duplicate:
What happens to memory after ‘\0’ in a C string?
Is it possible to make a pointer's, say, third element NUL ('\0'), thereafter "erasing" the pointers remaining elements?
Possible Duplicate:
What happens to memory after ‘\0’ in a C string?
Is it possible to make a pointer's, say, third element NUL ('\0'), thereafter "erasing" the pointers remaining elements?
Assuming you're talking about C-style strings then yes, kind of:
char s[] = "abcdefgh"; // s = "abcdefgh"
// (actually contains 9 characters: "abcdefgh\0")
s[3] = '\0'; // s = "abc"
// (still contains 9 characters, but now: "abc\0efgh\0")
Note that the characters beyond s[3]
haven't magically disappeared at this point - it's just that displaying the string, or passing it to any function that takes a C-style string, results in the string only appearing to contain three characters. You can still do e.g.
s[3] = 'x'; // s = "abcxefgh"
// (still contains 9 characters, but now: "abcxefgh\0")