ProgrammingVery hard
char s[] = "\x41\x42\0\x43"; printf("%zu", strlen(s)); What is printed?
- A. 3
- B. 4
- C. 5
- D. 2
Correct answer: D. 2
strlen stops at the first zero byte, which the \0 escape creates after the two hex-escaped letters. The C after it is never counted, although sizeof(s) is 5.
More C Programming questions
- char s[] = "banana"; char p = strrchr(s, 'a'); printf("%ld", (long)(p - s)); What is printed?
- printf("%zu", strcspn("aXbYc", "XY") + strspn(" 42ab", " 0123456789")); What is printed?
- 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?