ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
#define FOO 10
#define BAR FOO + 5
int main(void) {
int x = BAR * 2;
printf("%d", x);
}- A. 30
- B. 20
- C. 15
- D. 25
Correct answer: B. 20
BAR expands to FOO + 5, which itself expands to 10 + 5. So BAR * 2 expands fully to 10 + 5 * 2 = 10 + 10 = 20, since * binds tighter than the unparenthesized + inside BAR's expansion.
More C Programming questions
- 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]);
- What is printed? c int i = 1; int arr[5] = {0}; int x = i + i++; printf("%d", x);