ProgrammingVery hardProduct company OA
What is printed?
What is printed?
#define S(x) #x
printf("%zu %zu", strlen(S("hi")), sizeof(S(ab)));- A. 4 2
- B. 2 3
- C. 2 2
- D. 4 3
Correct answer: D. 4 3
Stringising an argument that is itself a string literal keeps its quotes, escaped: S("hi") becomes "\"hi\"", the 4 characters "hi" including both quote marks. S(ab) becomes "ab", whose sizeof is 3 including the '\0'.
More C Programming questions
- What is printed? c int paths(int r, int c) { return (r == 0 || c == 0) ? 1 : paths(r - 1, c) + paths(r, c - 1); } int main(void) {…
- Assume 8-bit unsigned char. What is printed? c int n = 0; for (unsigned char c = 0; c < 300; c++) { n++; if (n > 1000) break; }…
- Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed? c int big = 16777217; / 2^24 + 1 / float f = big; printf("%d"…
- Assume 8-bit unsigned char. What is printed? c int i; unsigned char c; double d; d = c = i = 300 + 0.7; printf("%d %d %.1f", i, c, d);
- Why is memcmp(&a, &b, sizeof a) == 0 an unreliable way to test whether two struct variables a and b have equal members?
- What is printed? c int c = 0; int f(int n) { c++; return n > 0 && (f(n - 1) || f(n - 2)); } int main(void) { int r = f(4); printf("%d %d"…