ProgrammingHard
char s[] = "x=1;y=2"; char *t = strtok(s, "="); printf("%s %zu", t, strlen(s)); What is printed?
- A. x 7
- B. x=1 7
- C. x=1 3
- D. x 1
Correct answer: D. x 1
strtok overwrites the delimiter with '\0', so the string is cut at the first token. strlen(s) becomes 1, and the rest of the array is hidden from it.
More C Programming questions
- Given char names[] holding strings, which qsort comparator sorts them alphabetically?
- char d[6] = "abc"; / we want strncat(d, "defgh", 5) with no overflow / What is the smallest size d needs?
- char b[16]; sprintf(b, "%d%%", 50); printf("%zu", strlen(b)); What is printed?
- printf("%c", 321); What is printed?
- char a[20], b[20]; / stdin: "hi therennextn" / scanf("%s", a); fgets(b, sizeof b, stdin); What is stored in b?
- char w[] = "ab", z[2] = "ab"; printf("%zu", sizeof w + sizeof z); What is printed?