250+ TOP MCQs on Macros and Answers

This section on C++ interview questions and answers on “Macros”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ interview questions on “Macros” along with answers, explanations and/or solutions:

1. which keyword is used to define the macros in c++?
a) macro
b) define
c) #define
d) #macro
Answer: c
Clarification: #define is the keyword which is used to define the macros in c++.

2. Which symbol is used to declare the preprocessor directives?
a) #
b) $
c) *
d) ^
Answer: a
Clarification: # symbol is used to declare the preprocessor directives.

3. How many types of macros are there in c++?
a) 1
b) 2
c) 3
d) 4
Answer: b
Clarification: There are two types of macros. They are object-like and function-like.

4. What is the mandatory preprocessor directive for c++?
a) #define
b) #include
c) #undef
d) #macro
Answer: b
Clarification: For a c++ program to execute, we need #include.

5. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     #define MIN(a,b) (((a)<(b)) ? a : b)
  4.     int main ()
  5.     {
  6.         float i, j;
  7.         i = 100.1;
  8.         j = 100.01;
  9.         cout <<"The minimum is " << MIN(i, j) << endl;
  10.         return 0;
  11.     }

a) 100.01
b) 100.1
c) compile time error
d) 100
Answer: a
Clarification: In this program, we are getting the minimum number using conditional operator.
Output:

$ g++ mac3.cpp
$ a.out
The minimum value is 100.01

6. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         cout << "Value of __LINE__ : " << __LINE__ << endl;
  6.         cout << "Value of __FILE__ : " << __FILE__ << endl;
  7.         cout << "Value of __DATE__ : " << __DATE__ << endl;
  8.         cout << "Value of __TIME__ : " << __TIME__ << endl;
  9.         return 0;
  10.     }

a) 5
b) details about your file
c) compile time error
d) runtime error
Answer: b
Clarification: 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

7. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     #define SquareOf(x) x * x
  4.     int main()
  5.     {
  6.         int x;
  7.         cout << SquareOf(x + 4);
  8.         return 0;
  9.     }

a) 16
b) 64
c) compile time error
d) 75386824
Answer: d
Clarification: In this program, as we have not initialize the variable x, we will get a output of ending digit of 4.
Output:

$ g++ mac1.cpp
$ a.out
75386824

8. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     #define PR(id) cout << "The value of " #id " is "<
  4.     int main()
  5.     {
  6.         int i = 10;
  7.         PR(i);
  8.         return 0;
  9.     }

a) 10
b) 15
c) 20
d) 12
Answer: a
Clarification: In this program, we are just printing the declared values.
Output:

9. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     #define MAX 10
  4.     int main()
  5.     {
  6.         int num;
  7.         num = ++MAX;
  8.         cout << num;
  9.         return 0;
  10.     }

a) 11
b) 10
c) compile time error
d) 13
Answer: c
Clarification: Macro Preprocessor only replaces occurance of macro symbol with macro symbol value, So we can’t increment the value.

10. What is the other name of the macro?
a) scripted directive
b) executed directive
c) link directive
d) executed & link directive
Answer: a
Clarification: When the compiler encounters a previously defined macro, it will take the result from that execution itself.

  250+ TOP MCQs on Function Call and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top