+ 2

c++ string,array

char isAString[6] = { 'H', 'e', 'l', 'l', 'o', '\0'}; char isNotAString[5] = { 'H', 'e', 'l', 'l', 'o'}; cout << isAString << endl; cout << isNotAString << endl; The most common mistake made by users of the C-style string is to forget to make the char array large enough to accommodate the \0 character, but also forgetting include the \0. In the previous example, a programmer might think that an array of size 5 would be large enough to contain Hello because that's how many characters are in the word. However, the null character would not be included in the second array, which could result in errors in code that uses this array. The reason is that C++ does not consider the isNotAString array to be a string. char isAString[6] = "Hello"; char isAnotherString[] = "Array size is inferred";

20th Apr 2019, 10:10 AM
Idris Abdellah
Idris Abdellah - avatar
5 Answers
+ 3
Thanks
20th Apr 2019, 11:06 AM
Idris Abdellah
Idris Abdellah - avatar
+ 3
Thank u very much
20th Apr 2019, 11:21 AM
Idris Abdellah
Idris Abdellah - avatar
+ 2
How to use the feed post 😊
20th Apr 2019, 11:09 AM
Idris Abdellah
Idris Abdellah - avatar