ProgrammingVery hardProduct company OA
What is printed?
What is printed?
#define A 1
#define B (A + 1)
#undef A
#define A 10
int main(void) {
printf("%d", B);
}- A. 2
- B. 10
- C. Compilation error
- D. 11
Correct answer: D. 11
Macro bodies are expanded at the point of USE, not at the point of definition. B expands to (A + 1); since A is used where it currently equals 10 (after the #undef/#define), B becomes (10 + 1) = 11.
More C Programming questions
- What is printed? c #define FOO 10 #define BAR FOO + 5 int main(void) { int x = BAR 2; printf("%d", x); }
- What is printed? c #define LOG(msg) printf("[LOG] %s line %dn", msg, LINE) int main(void) { LOG("start"); LOG("end"); }
- What is printed? c #define TRUE 1 #define FALSE 0 #define BOOL int BOOL flag = TRUE; int main(void) { if (flag == TRUE) printf("yes")…
- What is printed? c #define CLAMP(x, lo, hi) ((x) < (lo) ? (lo) : (x) > (hi) ? (hi) : (x)) int main(void) { printf("%d %d %d", CLAMP(5, 1…
- What is printed? Assume int is 32-bit, two's complement. c int x = INTMAX; int y = x + 1; printf("%d", y);
- What is the behavior? c int p = malloc(10 sizeof(int)); free(p); printf("%d", p[0]);