🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: String Handling in C: all 15 questions

Quiz: String Handling in C · Question 15 of 15

What does this print? (code)

What does this print?

#include <stdio.h>
#include <string.h>
int main(void) {
    char s[] = "red,,green,blue";
    int n = 0;
    for (char *t = strtok(s, ","); t != NULL; t = strtok(NULL, ",")) n++;
    printf("%d\n", n);
    return 0;
}
  1. A.4
  2. B.3
  3. C.2
  4. D.5
Answer & explanation

Correct answer: 3

strtok treats a run of delimiters as one separator, so the empty field between the two commas is skipped.

Can you get the rest right without peeking?

Take the timed Quiz: String Handling in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →