ProgrammingVery hardProduct company OA
What is printed?
What is printed?
#define f(x) ((x) * 2)
int (f)(int x) { return x + 100; }
int main(void) { printf("%d %d", f(1), (f)(1)); }- A. 2 2
- B. 101 101
- C. 2 101
- D. Compilation error
Correct answer: C. 2 101
A function-like macro expands only when its name is directly followed by '('. In (f)(1) and in the definition int (f)(int x), the name is followed by ')', so the real function is defined and called. Plain f(1) is the macro.
More C Programming questions
- What is printed? c if (strcmp("abc", "abc")) puts("same"); else puts("different");
- Assume ASCII. What is printed? c int x = 'A' + 1.5; printf("%c %d", x, x);
- Given int m[3][4];, why can m not be passed to a function declared void f(int p);?
- Assume C99 or later. What is printed? c void f(int n, int a[][n]) { printf("%zu", sizeof a[0] / sizeof a[0][0]); } int main(void) { int…
- What is printed? c int c = 0; for (int i = 1; i <= 10; i++) for (int j = i; i j <= 10; j++) c++; printf("%d", c);
- What does z("abcdef") print? c void z(const char s) { if (!s) return; putchar(s); z(s + 2); if (s[1]) putchar(s[1]); }