COMP1927 - Null Terminator Appendation

Character Arrays

If size is specified and there is at least one empty location for it

  • YES
    • A[7] = {‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’} = one spare space
    • B[100] = {‘a’, ‘a’, ‘a’, ‘a’} = lots of spare space
  • NO
    • C[3] = {‘c’, ‘c’, ‘c’} = no spare space
    • D[] = {‘d’, ‘d’, ‘d’, ‘d’, ‘d’} = no size specification

Strings

If there is a size & space or no size, or it’s a string pointer

  • YES
    • E[7] = “eeeeee” = size and space
    • F[] = “ffff” = no size
    • Char *g = “ggggg” = string pointer
  • NO
    • Char i[5] = “iiiii’ = size and no space

Null terminator is critical for string prints, comparisons, copy, generic manipulation.