ProgrammingVery hardProduct company OA
What is printed?
What is printed?
#define SCALE(x) (x * factor)
int factor = 3;
int f(void) { int factor = 10; return SCALE(2); }
int main(void) { printf("%d %d", f(), SCALE(2)); }- A. 6 20
- B. 20 6
- C. 6 6
- D. 20 20
Correct answer: B. 20 6
A macro is pasted as text and its names are looked up where it is used. Inside f, factor means the local 10, giving 20; in main it means the global 3, giving 6. A function would always use the global.
More C Programming questions
- What is printed? c int i = 0, n = 0; while (i++, i < 4) n += i; printf("%d %d", n, i);
- What is the range of values of a signed 8-bit two's-complement integer?
- What is printed? c unsigned x = 8; if (x & (x - 1) == 0) puts("pow2"); else puts("not");
- What is printed? c int m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, r[3][3]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++)…
- What is printed? c const char s = "banana", p = s; int c = 0; while ((p = strchr(p, 'a')) != NULL) { c++; p++; } printf("%d", c);
- Assume IEEE-754 double. What is printed? c printf("%d %d", 0.1 + 0.2 == 0.3, 0.5 + 0.25 == 0.75);