ProgrammingModerate
printf("%zu", strlen("a b c")); What is printed?
- A. 7
- B. 6
- C. 3
- D. 1
Correct answer: B. 6
strlen counts every character before the '\0', spaces included: a, space, b, space, space, c = 6. 7 adds the terminator as sizeof would, 3 counts only the letters, and 1 stops at the first space as scanf's %s would.
More C Programming questions
- char buf[16]; sprintf(buf, "%d-%d", 1, 22); printf("%zu", strlen(buf)); What is printed?
- char s[] = "abcd"; int n = strlen(s); for (int i = 0; i < n / 2; i++) { char t = s[i]; s[i] = s[n - 1 - i]; s[n - 1 - i] = t; }…
- char s[] = "a1B2-c"; int n = 0; for (char p = s; p; p++) if (isalpha((unsigned char)p)) n++; printf("%d", n); What is printed?
- char c = 'a' + 1; printf("%c", c); What is printed?
- printf("%5.3s|", "abcdef"); What is printed?
- printf("%d", 7 & ~2); What is printed?