Strings

C doesn't know what a string is! The common definition of a C string is a null-terminated character array, but C doesn't understand that definition either. There are however functions that are part of the C Standard Library that depend on that definition to work correctly. In fact, failure to null-terminate a C string will most likely result in a catastrophic end to the program.

But isn't Hi in the statement printf("Hi"); a string? No, not to C. The compiler stashes Hi in an array of 3 characters. Like this:

  • 1st Position of the array contains 'H'
  • 2nd position of the array contains 'i'
  • 3rd position of the array contains the null-termination character

    The is no way to declare a string variable in C. In order to properly handle strings, an understanding of Arrays and Pointers is required.