← 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;
}
- A.4
- B.3
- C.2
- 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 →