ProgrammingHardProduct company OA · TCS NQT
What is printed?
What is printed?
#define INC(x) x++; x++
int a = 0, b = 0;
if (a > 5) INC(b);
printf("%d", b);- A. 2
- B. 0
- C. 1
- D. Compilation error
Correct answer: C. 1
After expansion the code is `if (a > 5) b++; b++;`. The if controls only the first statement, so the second b++ always runs and b becomes 1. This is exactly the bug the do { } while (0) idiom prevents.
More C Programming questions
- What is printed? c int x = 7 / 2 2.0; double y = 7 / 2.0 2; printf("%d %.1f", x, y);
- What is printed? c void move(int pp) { (pp)++; pp += 10; } int main(void) { int a[] = {1, 2, 3}; int p = a; move(&p); move(&p); printf("%d…
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0xABCD; printf("%X %X", (x >> 4) & 0xF, (x & ~(0xFu << 8)) | (0x3u << 8));
- In C99, which declaration lets you allocate a rows × cols matrix of int (cols known at run time) with ONE malloc, use it as m[i][j], and…
- With 4-byte int, what is printed? c int a[4]; memset(a, 1, sizeof a); printf("%d", a[0]);
- What is printed? c struct N { int v; struct N nx; }; struct N c = {3, NULL}, b = {2, &c}, a = {1, &b}; struct N prev = NULL, cur = &a, nx…