Strings in C

C Strings are simply an array of "char" type elements. There is no length field.

  1. A C string must be terminated by a "\0" nul character. If you want a string of 10 characters you need to allocate 11 characters to make room for the nul character.

  2. String manipulation functions rely on the final nul character and will overwrite memory mercilessly if it is missing.

  3. Like java strings they are copied by reference. A string reference can be used to manipulate the string in any way.

  4. Like arrays strings can be allocated on the stack which makes allocation/deallocation extremely fast.

  5. The same memory management and responsibility rules as for arrays apply. This results in many programmers creating local copies of strings "just to make sure" that they own the memory behind.