ProgrammingHardTCS NQT · Infosys
char s[] = "hello"; printf("%zu %zu", sizeof s, strlen(s)); prints what?
- A. 5 5
- B. 6 6
- C. 5 6
- D. 6 5
Correct answer: D. 6 5
sizeof counts the terminating null character, giving 6. strlen counts characters before the terminator, giving 5.
More C Programming questions
- char names[] = {"ab", "cde", "f"}; What is strlen(names[0]) strlen(names[1]) + strlen(names[2])?
- 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?