ProgrammingVery hard
char buf[10]; int n = sprintf(buf, "%5.2f", 3.14159); printf("%d", n); What is printed?
- A. 4
- B. 6
- C. 5
- D. 10
Correct answer: C. 5
The output " 3.14" is padded to width 5 and has 5 characters, which sprintf returns. The terminator is not counted.
More C Programming questions
- char buf[10]; strncpy(buf, "abc", 10); int zeros = 0; for (int i = 0; i < 10; i++) if (buf[i] == 0) zeros++; printf("%d", zeros); What is…
- printf("%zu", sizeof("a" "bc")); What is printed?
- char c = 'a' + 25; printf("%c", c); What is printed on an ASCII system?
- int r = strcmp("abc", "abd"); What can be said about r according to the C standard?
- const char s = "abcabc"; printf("%ld", (long)(strstr(s, "ca") - s)); What is printed?
- char d[4] = "abc"; printf("%zu", sizeof d - strlen(d)); What is printed?