ProgrammingHardTCS NQT · Infosys
char *names[] = {"ab", "cde", "f"}; What is strlen(names[0]) * strlen(names[1]) + strlen(names[2])?
- A. 7
- B. 8
- C. 14
- D. 18
Correct answer: A. 7
strlen excludes the terminator and * binds tighter than +, so 2 * 3 + 1 = 7. 8 reads it as 2 * (3 + 1), 14 counts each '\0' as sizeof would (3 * 4 + 2), and 18 makes both mistakes.
More C Programming questions
- int add(int a, int b) { return a + b; } int sub(int a, int b) { return a - b; } int (ops[])(int, int) = {add, sub, add}; int r = 10; for…
- uint32t a = 4000000000u; uint32t s = a + a; What is s?
- uint32t lo = 3000000000u, hi = 3500000000u; uint32t mid = (lo + hi) / 2; What is mid?
- uint32t x = 0u; Which statement about the test (x & (x - 1)) == 0 is correct?
- uint8t x = 0x81; uint8t r = (uint8t)((x >> 1) | (x << 7)); What is r?
- What is the value of 1 << 2 + 3 in C?