LearnFrenzy
Sign in Take a free test

C Const · Predict the Output · Question 9

A const array of const strings – output Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

static const char *const colors[] = {"red", "green", "blue"};

int main(void) {
    printf("%s %c %zu\n", colors[1], colors[2][0], sizeof colors / sizeof colors[0]);
    return 0;
}
  • A green b 3 Correct
  • B green b 13
  • C red g 3
  • D green blue 3
Correct Answer: Option A

colors[1] is "green", colors[2][0] is the first character of "blue", and the array holds 3 pointers. Both the strings and the pointers are read-only, which is ideal for fixed tables.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links