MCQOPTIONS
Saved Bookmarks
This section includes 65 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Would the following work? |
| A. | Yes |
| B. | No |
| Answer» C. | |
| 2. |
Preprocessor directive can be used only on a macro that has been earlier |
| A. | True |
| B. | False |
| Answer» B. False | |
| 3. |
There exists a way to prevent the same file from getting twice in the same program. |
| A. | True |
| B. | False |
| Answer» B. False | |
| 4. |
Will the following program print the message infinite number of times? |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 5. |
Preprocessor directive .. ... is used for conditional compilation. |
| A. | True |
| B. | False |
| Answer» B. False | |
| 6. |
Will the program compile successfully? |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 7. |
Which of the following are correct preprocessor directives in C? |
| A. | 1, 2 |
| B. | 4 |
| C. | 1, 2, 4 |
| D. | 1, 2, 3, 4 |
| Answer» E. | |
| 8. |
Which of the following are correctly formed statements in C? |
| A. | #define CUBE (X) (X*X*X); |
| B. | #define CUBE(x) (X*X*X) |
| C. | #define CUBE(X)(X*X*X) |
| D. | #define CUBE(X) {X*X*X} |
| Answer» D. #define CUBE(X) {X*X*X} | |
| 9. |
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? |
| A. | It compiles |
| B. | Compiles with an warning |
| C. | Not compile |
| D. | Compiles and print nothing |
| Answer» D. Compiles and print nothing | |
| 10. |
In which stage the following code gets replaced by the contents of the file |
| A. | During editing |
| B. | During linking |
| C. | During execution |
| D. | During preprocessing |
| Answer» E. | |
| 11. |
Will the following program print the message infinite number of times?_x000D_ #include_x000D_ #define INFINITELOOP while(1)_x000D_ _x000D_ int main()_x000D_ {_x000D_ INFINITELOOP_x000D_ printf("IndiaBIX");_x000D_ return 0;_x000D_ } |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 12. |
What will be the output of the program? #include_x000D_ #define FUN(arg) do\_x000D_ {\_x000D_ if(arg)\_x000D_ printf("IndiaBIX...", "\n");\_x000D_ }while(--i)_x000D_ _x000D_ int main()_x000D_ {_x000D_ int i=2;_x000D_ FUN(i |
| A. | IndiaBIX... IndiaBIX... IndiaBIX |
| B. | IndiaBIX... IndiaBIX... |
| C. | Error: cannot use control instructions in macro |
| D. | No output |
| Answer» C. Error: cannot use control instructions in macro | |
| 13. |
What will be the output of the program?_x000D_ #include_x000D_ #define MAN(x, y) ((x)>(y)) ? (x):(y);_x000D_ _x000D_ int main()_x000D_ {_x000D_ int i=10, j=5, k=0;_x000D_ k = MAN(++i, j++);_x000D_ printf("%d, %d, %d\n", i, j, k);_x000D_ return 0;_x000D_ } |
| A. | 12, 6, 12 |
| B. | 11, 5, 11 |
| C. | 11, 5, Garbage |
| D. | 12, 6, Garbage |
| Answer» B. 11, 5, 11 | |
| 14. |
Point out the error in the program #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ int i;_x000D_ #if A_x000D_ printf("Enter any number:");_x000D_ scanf("%d", &i);_x000D_ #elif B_x000D_ printf("The number is odd");_x000D_ return 0;_x000D_ } |
| A. | Error: unexpected end of file because there is no matching #endif |
| B. | The number is odd |
| C. | Garbage values |
| D. | None of above |
| Answer» B. The number is odd | |
| 15. |
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?_x000D_ #include_x000D_ #define SWAP(a, b, c)(c t; t=a, a=b, b=t)_x000D_ int main()_x000D_ {_x000D_ int x=10, y=20;_x000D_ SWAP(x, y, int);_x000D_ printf("%d %d\n", x, y);_x000D_ return 0;_x000D_ } |
| A. | It compiles |
| B. | Compiles with an warning |
| C. | Not compile |
| D. | Compiles and print nothing |
| Answer» D. Compiles and print nothing | |
| 16. |
What will be the output of the program?_x000D_ #include_x000D_ #define SWAP(a, b) int t; t=a, a=b, b=t;_x000D_ int main()_x000D_ {_x000D_ int a=10, b=12;_x000D_ SWAP(a, b);_x000D_ printf("a = %d, b = %d\n", a, b);_x000D_ return 0;_x000D_ } |
| A. | a = 10, b = 12 |
| B. | a = 12, b = 10 |
| C. | Error: Declaration not allowed in macro |
| D. | Error: Undefined symbol 't' |
| Answer» C. Error: Declaration not allowed in macro | |
| 17. |
The output of the following program is:#define f(g,g2) g##g2void main(){int var12=100;printf("%d", f(var,12));} |
| A. | yntax error |
| B. | untime error |
| C. | ##g2 |
| D. | 00 |
| E. | 0012 |
| Answer» E. 0012 | |
| 18. |
What will be output after executing following code?#include# define a 10void main(){printf("%d..", a);foo();printf("%d", a);}void foo(){#undef a#define a 50} |
| A. | 0..50 |
| B. | 0..10 |
| C. | |
| Answer» C. | |
| 19. |
What will be the output of the following program?#include#define prod(a,b)a*bvoid main(){int x=3,y=4;printf("%d", prod(x+2,y-1));} |
| A. | 5 |
| B. | 2 |
| C. | 0 |
| D. | 1 |
| E. | one of these |
| Answer» D. 1 | |
| 20. |
Choose the correct statement.I.The scope of a macro definition need not be the entire program.II.The scope of a macro definition extends from the point of definition to the end of the file.III. New line is a macro definition delimiter.IV.A macro definition may go beyond a line. |
| A. | and II |
| B. | I and III |
| C. | , II and III |
| D. | I, III and IV |
| E. | , II, III and IV |
| Answer» F. | |
| 21. |
What will be the output of the program code?#include#define a 10void main(){#define a 50printf("%d", a);} |
| A. | 0 |
| B. | 0 |
| C. | ompiler Error |
| D. | one of These |
| Answer» B. 0 | |
| 22. |
What will be the output of the program?#include#define int charvoid main(){int i = 65;printf("sizeof(i)=%d", sizeof(i));} |
| A. | izeof(i)=2 |
| B. | izeof(i)=1 |
| C. | ompiler Error |
| D. | one of These |
| Answer» C. ompiler Error | |
| 23. |
Once preprocessing is over and the program is sent for the compilation the macros are removed from the expanded source code. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 24. |
A header file contains macros, structure declaration and function prototypes. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 25. |
What will be the output of the program? #include #define MESS junk int main() { printf("MESS\n"); return 0; } |
| A. | junk |
| B. | MESS |
| C. | Error |
| D. | Nothing will print |
| Answer» C. Error | |
| 26. |
What will be the output of the program? #include #define FUN(i, j) i##j int main() { int va1=10; int va12=20; printf("%d\n", FUN(va1, 2)); return 0; } |
| A. | 10 |
| B. | 20 |
| C. | 1020 |
| D. | 12 |
| Answer» C. 1020 | |
| 27. |
Preprocessor directive #ifdef .. #else ... #endif is used for conditional compilation. |
| A. | 1 |
| B. | |
| Answer» B. | |
| 28. |
What will be the output of the program? #include #define str(x) #x #define Xstr(x) str(x) #define oper multiply int main() { char *opername = Xstr(oper); printf("%s\n", opername); return 0; } |
| A. | Error: in macro substitution |
| B. | Error: invalid reference 'x' in macro |
| C. | print 'multiply' |
| D. | No output |
| Answer» D. No output | |
| 29. |
A preprocessor directive is a message from compiler to a linker. |
| A. | 1 |
| B. | |
| Answer» C. | |
| 30. |
Every C program will contain at least one preprocessor directive. |
| A. | 1 |
| B. | |
| Answer» C. | |
| 31. |
Macros have a local scope. |
| A. | 1 |
| B. | |
| Answer» C. | |
| 32. |
What will be the output of the program? #include #define PRINT(i) printf("%d,",i) int main() { int x=2, y=3, z=4; PRINT(x); PRINT(y); PRINT(z); return 0; } |
| A. | 2, 3, 4, |
| B. | 2, 2, 2, |
| C. | 3, 3, 3, |
| D. | 4, 4, 4, |
| Answer» B. 2, 2, 2, | |
| 33. |
What will be the output of the program? #include #define FUN(arg) do\ {\ if(arg)\ printf("IndiaBIX...", "\n");\ }while(--i) int main() { int i=2; FUN(i |
| A. | IndiaBIX... IndiaBIX... IndiaBIX |
| B. | IndiaBIX... IndiaBIX... |
| C. | Error: cannot use control instructions in macro |
| D. | No output |
| Answer» C. Error: cannot use control instructions in macro | |
| 34. |
The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces. |
| A. | 1 |
| B. | |
| Answer» C. | |
| 35. |
Macros with arguments are allowed |
| A. | 1 |
| B. | |
| Answer» B. | |
| 36. |
What will be the output of the program? #include #define MAX(a, b) (a > b ? a : b) int main() { int x; x = MAX(3+2, 2+7); printf("%d\n", x); return 0; } |
| A. | 8 |
| B. | 9 |
| C. | 6 |
| D. | 5 |
| Answer» C. 6 | |
| 37. |
What will be the output of the program? #include #define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) int main() { int x; x = MAX(3+2, 2+7, 3+7); printf("%d\n", x); return 0; } |
| A. | 5 |
| B. | 9 |
| C. | 10 |
| D. | 3+7 |
| Answer» D. 3+7 | |
| 38. |
Will it result in to an error if a header file is included twice? |
| A. | Yes |
| B. | No |
| C. | It is compiler dependent. |
| Answer» D. | |
| 39. |
What will be the output of the program? #include #define SWAP(a, b) int t; t=a, a=b, b=t; int main() { int a=10, b=12; SWAP(a, b); printf("a = %d, b = %d\n", a, b); return 0; } |
| A. | a = 10, b = 12 |
| B. | a = 12, b = 10 |
| C. | Error: Declaration not allowed in macro |
| D. | Error: Undefined symbol 't' |
| Answer» C. Error: Declaration not allowed in macro | |
| 40. |
It is necessary that a header files should have a .h extension? |
| A. | Yes |
| B. | No |
| Answer» C. | |
| 41. |
A macro must always be defined in capital letters. |
| A. | 1 |
| B. | |
| C. | 1 |
| D. | |
| Answer» C. 1 | |
| 42. |
What will be the output of the program? #include #define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2); int main() { char *str1="India"; char *str2="BIX"; JOIN(str1, str2); return 0; } |
| A. | str1=IndiaBIX str2=BIX |
| B. | str1=India str2=BIX |
| C. | str1=India str2=IndiaBIX |
| D. | Error: in macro substitution |
| Answer» C. str1=India str2=IndiaBIX | |
| 43. |
What will be the output of the program? #include #define SQR(x)(x*x) int main() { int a, b=3; a = SQR(b+2); printf("%d\n", a); return 0; } |
| A. | 25 |
| B. | 11 |
| C. | Error |
| D. | Garbage value |
| Answer» C. Error | |
| 44. |
What will be the output of the program? #include #define MIN(x, y) (x 0) printf("%d\n", z); return 0; } |
| A. | 3 |
| B. | 4 |
| C. | 0 |
| D. | No output |
| Answer» B. 4 | |
| 45. |
What will be the output of the program? #include #define CUBE(x) (x*x*x) int main() { int a, b=3; a = CUBE(b++); printf("%d, %d\n", a, b); return 0; } |
| A. | 9, 4 |
| B. | 27, 4 |
| C. | 27, 6 |
| D. | Error |
| Answer» D. Error | |
| 46. |
Will the program compile successfully? #include int main() { #ifdef NOTE int a; a=10; #else int a; a=20; #endif printf("%d\n", a); return 0; } |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 47. |
What will be the output of the program? #include #define PRINT(int) printf("int=%d, ", int); int main() { int x=2, y=3, z=4; PRINT(x); PRINT(y); PRINT(z); return 0; } |
| A. | int=2, int=3, int=4 |
| B. | int=2, int=2, int=2 |
| C. | int=3, int=3, int=3 |
| D. | int=4, int=4, int=4 |
| Answer» B. int=2, int=2, int=2 | |
| 48. |
Will the program compile successfully? #include int main() { printf("India" "BIX\n"); return 0; } |
| A. | Yes |
| B. | No |
| Answer» B. No | |
| 49. |
Which of the following are correctly formed #define statements in C? |
| A. | #define CUBE (X) (X*X*X); |
| B. | #define CUBE(x) (X*X*X) |
| C. | #define CUBE(X)(X*X*X) |
| D. | #define CUBE(X) {X*X*X} |
| Answer» D. #define CUBE(X) {X*X*X} | |
| 50. |
Would the following typedef work? typedef #include l; |
| A. | Yes |
| B. | No |
| Answer» C. | |