ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int x = 5;
#define x (x + 1)
printf("%d", x);- A. 5
- B. 7
- C. Nothing: the preprocessor loops forever
- D. 6
Correct answer: D. 6
A macro's name is not re-expanded inside its own replacement, so x becomes (x + 1) once, and that inner x is the variable. The declaration int x = 5 came before the #define and is unaffected. Self-reference is how such macros avoid infinite expansion.
More C Programming questions
- What is printed? c int c = 0; for (int i = 1; i <= 16; i = 2) for (int j = 0; j < i; j++) c++; printf("%d", c);
- What is printed? c int i, c = 0; for (i = 0; i < 10; i += i + 1) c++; printf("%d %d", c, i);
- What is printed? c int a = 2, b = 4; printf("%d %d %d", a & b, a && b, a | b);
- What is printed? c int z(int n) { return n < 5 ? 0 : n / 5 + z(n / 5); } int main(void) { printf("%d %d", z(100), z(125)); }
- What is printed? c int next(void) { static int n; return n += 2; } int prev(void) { static int n = 10; return n -= 3; } int main(void) {…
- What is printed? c void rev(char a, char b) { while (a < b) { char t = a; a++ = b; b-- = t; } } int main(void) { char s[] = "abc de"…