-1
 char* str = “ABC\n”;

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

Achrome
  • 7,773
  • 14
  • 36
  • 45
Arch1tect
  • 4,128
  • 10
  • 48
  • 69

3 Answers3

3

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

Achrome
  • 7,773
  • 14
  • 36
  • 45
2

3 bytes for A, B, and C, 1 for the newline and one for the null, aka \0 character.

Sotiris Kal.
  • 68
  • 1
  • 6
0

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.