ProgrammingModerate
char s[] = "a,,b,c"; int n = 0; for (char *t = strtok(s, ","); t != NULL; t = strtok(NULL, ",")) n++; printf("%d", n); What is printed?
- A. 2
- B. 4
- C. 3
- D. 5
Correct answer: C. 3
strtok skips runs of delimiters, so the empty field between the two commas gives no token. Only 'a', 'b' and 'c' are returned.
More C Programming questions
- char d[8] = "ab"; strncat(d, "cdefgh", 3); printf("%zu", strlen(d)); What is printed?
- Which statement about the value returned by strcmp("apple", "Apple") is guaranteed by the C standard?
- char s[] = "abcdef"; memmove(s + 2, s, 4); printf("%s", s); What is printed?
- char a[10] = "hi"; printf("%zu", sizeof(a) - strlen(a) - 1); What is printed?
- char s[] = "xyz"; char p = s; p[0] = 'a'; printf("%s %zu", s, sizeof s); What is printed?
- char b[4]; int r = snprintf(b, 4, "%d", 123456); printf("%d %s", r, b); What is printed?