C Programming Multiple Choice Question - Preprocessor And Macros
This section focuses on the "Preprocessor And Macros" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. What is the output of this program?
#include <stdio.h>
#define int char
main()
{
int i=50;
printf ("sizeof (i) =%d", sizeof (i));
}
A. 2
B. 4
C. 8
D. 1
View Answer
Ans : D
Explanation: Since the #define replaces the string int by the macro char
2. What is the output of this program?
#include <stdio.h>
#define x 3
int main()
{
int i;
i = x*x*x;
printf("%d",i);
return 0;
}
A. 27
B. x is not declared
C. No output
D. Garbage value
View Answer
Ans : A
Explanation: Since we replace x = 27 in #define.
3. What is the output of this program?
#include <stdio.h>
#include <stdlib.h>
#define square(x) x*x
int main()
{
int i;
i = 27/square(3);
printf("%d",i);
return 0;
}
A. 9
B. Compilation error
C. 3
D. 27
View Answer
Ans : D
Explanation: Operators enjoys priority / is given more priority over *. In this program the execution takes place in this format.
27 / square(3)
27 / 3*3
27 / 3*3
9 * 3
27
4. What is the output of this program?
#include <stdio.h>
#define i 5
int main()
{
#define i 10
printf("%d",i);
return 0;
}
A. Compilation error
B. 10
C. 5
D. Runtime error
View Answer
Ans : B
Explanation: The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value (#define i 10) will be taken.
5. What is the output of this program?
#include <stdio.h>
#define clrscr() 17
int main()
{
clrscr();
printf("%d",clrscr());
return 0;
}
A. Compilation error
B. Runtime error
C. 17
D. none of the above
View Answer
Ans : C
Explanation: Preprocessor in any programming language executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 17 occurs with no errors.
6. What is the output of this program?
#include <stdio.h>
int main()
{
printf("%d",30);
return 0;
}
A. Runtime Error
B. Garbage value
C. Compilation error
D. 30
View Answer
Ans : C
Explanation: Expected unqualified-id before numeric constant error will occur. Though 30; is an executable statement inside main() function, it won't outside the main() function.
7. What is the output of this program?
#include <stdio.h>
#define p 17;
int main()
{
printf("%d",p);
return 0;
}
A. Garbage value
B. Runtime error
C. 17
D. Compilation error
View Answer
Ans : D
Explanation: Preprocessor should not terminate with semicolon.
8. Which statment is true about the given code ?
#include <stdio.h>
enum colors {lets,find,course};
int main()
{
printf("%d %d %d",course,lets,find);
return 0;
}
A. 3 1 2
B. 0 1 2
C. 2 0 1
D. 1 0 2
View Answer
Ans : C
Explanation: enum assigns numbers starting from 0, if not explicitly defined by some other integer.
9. What is the Error of this program?
#include <stdio.h>
#define CONDITION(x)
printf("letsfindcourse");
int main()
{
CONDITION(0);
return 0;
}
A. letsfindcourse
B. Compilation error
C. Runtime error
D. None of the above
View Answer
Ans : B
Explanation: #define CONDITION(x) must be terminated my backslash () to follow the next line.
10. How will you free the memory allocated by the following program?
#include <stdio.h>
#define CONDITION(x)
printf("letsfindcourse");
int main()
{
CONDITION(0);
return 0;
}
A. Runtime Error
B. letsfindcourse
C. Compilation error
D. None of the above
View Answer
Ans : B
Explanation: #define CONDITION(x) ends with backslash(/). So that next line following #define CONDITION(x) will be consider by the C compiler and prints letsfindcourse.
11. What is a preprocessor directive
A. a message from compiler to the programmer
B. a message from programmer to the microprocessor
C. a message from programmer to the preprocessor
D. a message from compiler to the linker
View Answer
Ans : C
Explanation: preprocessor directive is a message from programmer to the preprocessor.
12. Which of the following are correctly formed #define statements?
A. #define INCH PER FEET 12
B. #define SQR(X) (X *X);
C. #define SQR(X) X*X
D. #define SQR(X) (X*X)
View Answer
Ans : D
Explanation: #define SQR(X) (X *X) correctly formed #define statements
13. A macro must always be written in capital letters.
A. TRUE
B. May Be
C. FALSE
D. Can't Say
View Answer
Ans : B
Explanation: The statement is false
14. A macro should always be accommodated in a single
line.
A. TRUE
B. May Be
C. FALSE
D. Can't Say
View Answer
Ans : A
Explanation: Usually true. Some compilers allow multi-line macros
15. After preprocessing when the program is sent for
compilation the macros are removed from the expanded source code.
A. TRUE
B. FALSE
C. Can be true or false
D. Can't Say
View Answer
Ans : A
Explanation: The statement is True.
16. Macros with arguments are not allowed.
A. TRUE
B. May Be
C. FALSE
D. Can't Say
View Answer
Ans : B
Explanation: The statement is false
17. Nested macros are allowed.
A. TRUE
B. May Be
C. FALSE
D. Can't Say
View Answer
Ans : B
Explanation: The statement is false
18. Tn a macro call the control is passed to the macro.
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : B
Explanation: The statement is false
19. All macro substitutions in a program are done?
A. Before compilation of the program.
B. During execution
C. After compilation
D. None of the above
View Answer
Ans : A
Explanation: All macro substitutions in a program are done Before compilation of the program.
20. In a program the statement:
#include "filename"
is replaced by the contents of the file "filename"?
A. Before compilation
B. During execution
C. After Compilation
D. None of the above
View Answer
Ans : A
Explanation: Before compilation is the answer.
21. Identify the trigraph sequence for .
A. ??/
B. ??=
C. ??
D. ??!
View Answer
Ans : A
Explanation: The trigraph sequence for is ??/
22. Identify the trigraph sequence for^.
A. ??/
B. ??=
C. ??
D. ??!
View Answer
Ans : C
Explanation: The trigraph sequence for ^ is ??
23. What is the output generated by the following code?
    #define square (a) (a*a)
    printf("%d", square (4+5) ) ;
A. 81
B. 4
C. 29
D. None of the above.
View Answer
Ans : C
Explanation: the output generated by the following code is 29.
24. Undefined function calls in a C program.
A. by the preprocessor
B. by the linker
C. by the assembler
D. by the operating system are detected
View Answer
Ans : C
Explanation: Undefined function calls in a C program by the assembler.
25. Identify the macro(s) defined in stdarg.h.
A. va_start
B. va_end
C. va_arg
D. all the above
View Answer
Ans : D
Explanation: The macro(s) defined in stdarg.h is all.
26. va_list is
A. a macro defined in stdarg.h
B. a predefined data type in stdarg.h
C. a macro defined in stdlib.h
D. a predefined data type stdlib.h.
View Answer
Ans : B
Explanation: a predefined data type in stdarg.h
27. The following line in a program # represents
A. an invalid code
B. a null directive
C. a comment
D. a page number
View Answer
Ans : B
Explanation: The following line in a program # represents a null directive.
28. Identify the stringizing operator.
A. +
B. ::
C. #
D. ##
View Answer
Ans : C
Explanation: # the stringizing operator.
29. The EOF character can be included in a file as part of its data
A. TRUE
B. May Be
C. FALSE
D. Can't Say
View Answer
Ans : B
Explanation: No, The EOF character can not be included in a file as part of its data.
30. The NULL character indicates an end of a string and a file.
A. TRUE
B. May Be
C. FALSE
D. Can't Say
View Answer
Ans : B
Explanation: No, The NULL character did not indicates an end of a string and a file.
Also check :
Discussion