ProgrammingHardProduct company OA
What is printed?
What is printed?
const char *s = "abcdefgh";
const char *p = s + 2, *q = strchr(s, 'g');
printf("%td %c %s", q - p, *(p + (q - p) / 2), q);- A. 4 e g
- B. 4 e gh
- C. 5 e gh
- D. 4 d gh
Correct answer: B. 4 e gh
p points at 'c' (index 2) and q at 'g' (index 6), so q − p = 4. The midpoint is p + 2, index 4, 'e'. Printing q with %s prints from 'g' to the end: "gh".
More C Programming questions
- Given int f(int); and int (fp)(int) = f; which of these calls are valid? (i) fp(2) (ii) (fp)(2) (iii) (fp)(2) (iv) (&fp)(2)
- What is printed? c union U { int i; float f; } u = {3.9}; printf("%d", u.i);
- What is printed? c int i = 0, c = 0; while (i < 10 && ++c && i++ % 3 != 2); printf("%d %d", i, c);
- Given this allocation, which code frees everything without leaking or touching freed memory? c int m = malloc(3 sizeof m); for (int i = 0…
- With char a = "hi", b = "hi"; what can be said about the value of a == b?
- What is printed? c int c = 0; for (int i = 1; i <= 4; i++) for (int j = i; j <= 4; j += i) c++; printf("%d", c);