Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
char* str = “ABC\n”;
当被问到“为这个字符串分配了多少个字符?” 为什么答案是 5?
3 个字母字符 + 1 个转义字符 + 1 个字符串结尾 [ \0] 字符
\0
3 个字节用于 A、B 和 C,1 个用于换行符,1 个用于空字符,即 \0 字符。
3 Albhabets (ABC) 和一个新行(\n),最后为 null(或字符串结尾),即 \0。
所以总数是五个。