Question related to Strings in C language

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepp
    New Member
    • Jul 2007
    • 3

    Question related to Strings in C language

    In C all the Strings end with \0 character.
    My question is who will and when this character get appended.
    I mean which part of compilation process.

    Please help me to understand this.
  • ruskalym
    New Member
    • Sep 2007
    • 65

    #2
    '\0' is implicitly appended when using hard coded strings : "bla string".

    Most of string processing functions assume there is a terminal '\0' at the end of input string, and append it to output string too.

    If there was no '\0', functions wouldn't know where does the string end and would read next bytes in memory until it finds a NULL character or triggers a page fault.

    Comment

    • mschenkelberg
      New Member
      • Jun 2007
      • 44

      #3
      All of the functions I/O functions will null terminate, like scanf, fscanf, fgets, also all of the str functions will null terminate, strcpy, strcat, etc...
      cppreference.co m

      Comment

      Working...