1. ► What is the output of the following program?
1 2 3 4 5 6 7 8
#define MAX(x, y) x>y ? 1: 0 int main() { int i = 9; printf("%d", MAX(10, i) + 1); }
2. ► What is the output of the following program?
1 2 3 4 5 6 7 8 9
#define DIGIT1 110 #define DIGIT2 20 int main() { char *s = "DIGIT1 > DIGIT2"; printf("%s", s); }
3. ► Compiler gives error while compiling the following program. Why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#define INCR(i, j) \ { i++; \ j++; } int main() { int i = 10, j = 20; if (1) INCR(i, j); else INCR(j, i); printf("%d", i); }
4. ► What is the output of the following program?
#define INCR(i, j) \ i++; \ j++ int main() { int i = 10, j = 20; if (1) INCR(i, j); else INCR(j, i); printf("%d", i); }
5. ► What is the output of the following program?
#define DIGIT1 110 #define DIGIT2 20 int main() { int i = DIGIT1 > DIGIT2; printf("%d", i); }
6. ► What is the output of the following program?
#define MACRO1(arg) #arg #define MACRO2 20 #define MACRO3 MACRO1(110) int main() { printf("%d", MACRO3); }
7. ► What is the output of the following program?
#define MAX(x, y) (x>y ? 1: 0) int main() { int i = 20; printf("%d", MAX(10, i)); }
8. ► Compiler can perform typechecking on macros.
9. ► Which of the following option is used to pass on macro value on command line?
10. ► What is the output of the following program?
1 2 3 4 5 6
#define STR(mystr) mystr##_s int main() { printf("%s", STR(name)); }
11. ► What is the output of the following program?
1 2 3 4 5 6 7 8 9 10 11 12 13
#define ARRAY int main() { int i = 20; #if defined ARRAY i++; #else i--; #endif printf("%d", i); }
12. ► Which of the following tools expands macros.
13. ► Macros are language constructs.
14. ► Inline functions are preferred over macros.
15. ► What is the output of the following program?
#define MACRO1(arg) #arg #define MACRO2 20 #define MACRO3 MACRO1(110) int main() { printf("%d", MACRO3 > MACRO2); }
16. ► #include can occur only at the top of the file.
17. ► What is the output of the following program?
#define INCR(x) x + 1 int main() { int i = INCR(10) * 2; printf("%d", i); }
18. ► A debugger can set the breakpoint within macro.
19. ► Which of the following option helps in viewing exapanded macros?
20. ► Each macro starts with char ‘#’ .