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";

  1. A.

    5 bytes

  2. B.

    6 bytes

  3. C.

    7 bytes

  4. 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.

Explore the full course: Hexaware Preparation