ProgrammingHardTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
int main(void) {
    const char *s = "112233";
    int count[10] = {0};
    for (const char *p = s; *p; p++)
        count[*p - '0']++;
    printf("%d", count[2]);
}
  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

Each character's digit value indexes the count array, and the digit 2 occurs twice in 112233.

More C Programming questions

Exams that ask this topic