ProgrammingHardTCS NQT · Infosys
char buf[5] = "abcd"; printf("%zu", sizeof(buf) - strlen(buf)); What is printed?
- A. 5
- B. 4
- C. 0
- D. 1
Correct answer: D. 1
sizeof(buf) is 5 and strlen(buf) is 4, so the difference is 1. The terminator is included in the array size but not in strlen.
More C Programming questions
- int a[5] = {0}; int p = a + 5; p[-1] = 7; printf("%d", a[4] + (a + 4)); What is printed?
- The sorted array is {1, 3, 3, 3, 7, 9}. What is the index of the first element that is at least 4?
- A qsort comparator compares double values with (x > y) - (x < y). After sorting {2.5, -1.0, 2.25}, which value is last?
- Merge sort merges two halves with n element comparisons, so T(n) = 2T(n/2) + n and T(1) = 0. What is T(8)?
- unsigned int x = 1u; x = ~x; What is x?
- unsigned int u = 5u; int s = -5; printf("%s", (u + s == 0) ? "yes" : "no"); What is printed?