ProgrammingHardTCS NQT · Infosys
char *s = "hello"; What is strlen(s + 2)?
- A. 5
- B. 2
- C. 3
- D. 4
Correct answer: C. 3
s + 2 points at "llo", which has three characters before the terminator. The result is 3.
More C Programming questions
- int x = 1, y = 2, z = 3; int ptrs[3] = {&x, &y, &z}; What is ptrs[1] + ptrs[2]?
- printf("%d", 0x7FFFFFFF == 2147483647); What is printed?
- unsigned char c = 0xFF; unsigned int u = c << 8 | c; printf("%X", u); What is printed?
- static int total = 0; int add(int n) { static int t = 0; t += n; return t; } Calls add(3), add(4) and add(5) in that order. What does the…
- int r = 0; switch (2) { case 1: r += 1; case 2: r += 10; case 3: r += 100; break; default: r += 1000; } What is r?
- for (int i = 0, j = 10; i < j; i += 3, j -= 3) count++; How many times does the body run?