ProgrammingVery hard
printf("%zu", strcspn("aXbYc", "XY") + strspn(" 42ab", " 0123456789")); What is printed?
- A. 4
- B. 5
- C. 6
- D. 7
Correct answer: B. 5
strcspn counts the leading characters outside the second set, which is 1 here (it stops at 'X'). strspn counts the leading characters inside the set, which is 4 for the two spaces, '4' and '2'. 1 + 4 = 5.
More C Programming questions
- A naive strstr-style search looks for a pattern of length m = 50000 in a text of length n = 100000. The text is all 'a' and the pattern is…
- What does strncmp("abc", "xyz", 0) return?
- char a[3] = {'x', 'y', 'z'}; Which call reads a correctly with no undefined behaviour?
- char a = "", b = "abc"; if (strlen(a) - strlen(b) > 0) puts("longer"); else puts("not longer"); What is printed?
- In C (not C++), what is sizeof('A')?
- char a[5] = "hi"; printf("%d", a[4]); What is printed?