ProgrammingModerate
char buf[16]; sprintf(buf, "%d-%d", 1, 22); printf("%zu", strlen(buf)); What is printed?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
sprintf writes "1-22" into buf, and strlen counts its four characters but not the terminator. 5 adds the '\0', and 3 forgets that 22 has two digits.
More C Programming questions
- 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?
- printf("%d", (1 << 4) | (1 << 2)); What is printed?