char* str = “ABC\n”;
When asked "How many characters are allocated for this string?" why is the answer 5?
3 alphabetic characters + 1 escape character + 1 end of string [\0
] character
3 bytes for A, B, and C, 1 for the newline and one for the null, aka \0 character.
3 Albhabets (ABC) and one new line (\n) and last for null (or end of the string) i.e. \0.
So the total is five.