ProgrammingHardProduct company OA
What value does this call to printf return?
What value does this call to printf return?
printf("%5.1f|%-5d|", 3.14159, 42);- A. 14
- B. 10
- C. 12
- D. 9
Correct answer: C. 12
%5.1f prints " 3.1" (width 5), %-5d prints "42 " (left-justified, width 5), and there are two '|' characters: 5 + 1 + 5 + 1 = 12. printf returns the number of characters written.
More C Programming questions
- What is printed? c const char w[] = {"red", "green", "blue", "cyan"}; const char p[] = {w + 2, w, w + 3, w + 1}; const char q = p…
- What is printed? c int m(int n) { return n > 100 ? n - 10 : m(m(n + 11)); } int main(void) { printf("%d %d", m(50), m(105)); }
- What is printed? c int h(unsigned a, unsigned b) { int c = 0; for (unsigned x = a ^ b; x; x >>= 1) c += x & 1; return c; } int main(void)…
- What is printed? c int a[] = {10, 20, 30, 40, 50}; int p = &a[3]; printf("%d %d %d", p[-2], -1[p], (p - 1)[-1]);
- What is printed? c struct C { int r, g, b; } c = {.b = 9, .r = 4}; printf("%d %d %d", c.r, c.g, c.b);
- Assume 4-byte int with 4-byte alignment. What is printed? c union U { char c[5]; int i; }; printf("%zu", sizeof(union U));