ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
char w[][6] = {"red", "green", "blue"};
printf("%zu %zu %zu", sizeof(w), sizeof(w[1]), strlen(w[1]));
  1. A. 18 6 6
  2. B. 24 8 5
  3. C. 18 6 5
  4. D. 15 6 5

Correct answer: C. 18 6 5

w is a real 2-D array of 3 rows of 6 chars, so sizeof(w) = 18 and each row is 6 bytes, whatever string it holds. strlen("green") is 5. '24 8 5' would be an array of 3 pointers on a 64-bit machine, which this is not.

More C Programming questions

Exams that ask this topic