When the compiler encounters a previously defined macro, it will take the result from that
execution itself.
Question 2.
What is the output of this program?
1. #include 2. using namespace std; 3. #define MAX 4. int main() 5. { 6. int num; 7. num = ++MAX; 8. cout
11
10
compile time error
none of the mentioned
Explanation:-
Answer: Option C. -> compile time error
:Macro Preprocessor only replaces occurance of macro symbol with macro symbol value,
So we can’t increment the value.
Question 3.
What is the output of this program?
1. #include 2. using namespace std; 3. #define SquareOf(x) x * x 4. int main() 5. { 6. int x; 7. cout
16
64
compile time error
none of the mentioned
Explanation:-
Answer: Option D. -> none of the mentioned
In this program, as we haven't initiailzed the variable x, we will get a output of ending digit of 4. Output: $ g++ mac1.cpp $ a.out 75386824
Question 4.
What is the output of this program?
1. #include 2. using namespace std; 3. int main () 4. { 5. cout
5
Details about your file
compile time error
none of the mentioned
Explanation:-
Answer: Option B. -> Details about your file
In this program, we are using the macros to print the information about the file. Output: $ g++ mac2.cpp $ a.out Value of __LINE__ : 5 Value of __FILE__ : mac1.cpp Value of __DATE__ : Oct 10 2012 Value of __TIME__ : 22:24:37
Question 5.
What is the output of this program?
1. #include 2. using namespace std; 3. #define MIN(a,b) (((a)
100.01
100.1
compile time error
none of the mentioned
Explanation:-
Answer: Option A. -> 100.01
:In this program, we are getting the minimum number using conditional operator. Output: $ g++ mac3.cpp $ a.out The minimum value is 100.01
Question 6.
How many types of macros are there in c++?
1
2
3
4
Explanation:-
Answer: Option B. -> 2
There are two types of macros. They are object-like and function-like.
Question 7.
which keyword is used to define the macros in c++?
macro
define
#define
none of the mentioned
Explanation:-
Answer: Option C. -> #define
None.
Question 8.
What is the mandatory preprosessor directive for c++?
#define
#include
#undef
none of the mentioned
Explanation:-
Answer: Option B. -> #include
For a c++ program to execute, we need #include.
Question 9.
Which symbol is used to declare the preprocessor directives?