ProgrammingVery hard
printf("%d", strlen("a\0b")); What is printed?
- A. 2
- B. 3
- C. 0
- D. 1
Correct answer: D. 1
The \0 escape ends the string after 'a', so strlen returns 1 even though the literal holds three characters plus a terminator.
More C Programming questions
- char s = "x"; char t[2] = {'y', '0'}; int r = strcmp(s, t); What does r look like?
- printf("[%03d]", 7); What is printed?
- printf("[%5s|%-5s]", "ab", "cd"); What is printed?
- printf("%x %o", 255, 8); What is printed?
- char s[5] = "abcd"; printf("%s", s + 2); What is printed?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%c%c%c%c", 'w', 'x', 'y', 'z'); printf("%d %s", n, buf); What is printed?