Size of the character array should be one larger than number of characters in string - C++

Q.  In CPP, the size of the character array should be one larger than the number of characters in the string.

- Published on 17 Jul 15

a. True
b. False

ANSWER: True
 

    Discussion

  • ?????   -Posted on 23 Feb 16
    this is required to store the null terminating character.
  • Raj Singh   -Posted on 13 Oct 15
    String is represented as a character array, which is terminated by a null character '\0'. Actually, you do not place the null character at the end of a string constant. The C++ compiler automatically places the '\0' at the end of the string when it initializes the array. Due to this this null character, array should be one larger than the number of characters in the string.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)