How many bytes are occupied by the following string? char str[] = "abcdef";
20232023
How many bytes are occupied by the following string?
char str[] = "abcdef";
- A.
5 bytes
- B.
6 bytes
- C.
7 bytes
- D.
8 bytes
Attempted by 90 students.
Show answer & explanation
Correct answer: C
The string "abcdef" is made of 6 characters. Each character in C occupies 1 byte. Additionally, C strings are null-terminated, requiring an extra byte for the null character (\0). Therefore, the total space occupied is 7 bytes.