Search code examples
ccstring

C-string size including null terminater


 char* str = “ABC\n”;

When asked "How many characters are allocated for this string?" why is the answer 5?


Solution

  • 3 alphabetic characters + 1 escape character + 1 end of string [\0] character