ProgrammingModerateTCS NQT · Infosys
char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); What is n?
- A. 3
- B. 4
- C. 5
- D. 12345
Correct answer: C. 5
snprintf returns the length the full output would have had, which is 5, even though only three digits and the terminator fit in buf. Checking the return value is how you detect truncation.
More C Programming questions
- uint8t x = 0xB7; uint8t y = x | (x + 1); What is y?
- The number of ways to tile a 2 x 6 board with 2 x 1 dominoes equals the number of binary tilings given by T(n) = T(n-1) + T(n-2) with T(1)…
- Intervals (1,4), (2,3) and (3,5) are stored as pairs in an array and qsort sorts them ascending by their second value. Which pair comes…
- Which of these statements are well defined by the C standard? I. uint8t x = 255; x = x + 1; leaves x equal to 0. II. int a = INTMAX; a + 1…
- What is the sum of the decimal digits of 2^20 = 1048576?
- uint16t a = 40000, b = 40000; uint32t s = a + b; What is s?