C++ interview questions and answers focuses on “Macros”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews 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.

C++ interview questions on “Macros” along with answers, explanations and/or solutions:

Q 1. which keyword is used to define the macros in c++?
A. macro
B. define
C. #macro
D. #define

Show Answer Answer:-D. #define
Explanation #define is the keyword which is used to define the macros in c++.

Q 2. Which symbol is used to declare the pre-processor directives?
A. #
B. $
C. *
D. ^

Show Answer Answer:-A. #
Explanation # symbol is used to declare the pre-processor directives.

Q 3. How many types of macros are there in c++?
A. 1
B. 2
C. 3
D. 4

Show Answer Answer:-B. 2
Explanation There are two types of macros. They are object-like and function-like.

Q 4. What is the mandatory pre-processor directive for c++?
A. #include <iostream>
B. #define <iostream>
C. #undef <iostream>
D. #macro <iostream>

Show Answer Answer:-A. #include
Explanation For a c++ program to execute, we need #include.

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

#include <iostream>

using namespace std;

#define MIN(a,b) (((a)<(b)) ? a : b)

int main ()

{

float i, j;

i = 100.1;

j = 100.01;

cout <<“The minimum is ” << MIN(i, j) << endl;

return 0;

}

A. 100.01
B. 100.1
C. compile time error
D. 100

Show Answer Answer:-A. 100.01
Explanation In this program, we are getting the minimum number using conditional operator. Output: $ g++ mac3.cpp $ a.out The minimum value is 100.01

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

#include <iostream>

using namespace std;

int main ()

{

cout << “Value of __LINE__ : ” << __LINE__ << endl;

cout << “Value of __FILE__ : ” << __FILE__ << endl;

cout << “Value of __DATE__ : ” << __DATE__ << endl;

cout << “Value of __TIME__ : ” << __TIME__ << endl;

return 0;

}

A. 5
B. runtime error
C. compile time error
D. details about your file

Show Answer Answer:-D. details about your file
Explanation 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

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

#include <iostream>

using namespace std;

#define SquareOf(x) x * x

int main()

{

int x;

cout << SquareOf(x + 4);

return 0;

}

A. 16
B. 64
C. compile time error
D. 75386824

Show Answer Answer:-D. 75386824
Explanation 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

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

#include <iostream>

using namespace std;

#define PR(id) cout << “The value of ” #id ” is “<<id

int main()

{

int i = 10;

PR(i);

return 0;

}

A. 10
B. 15
C. 20
D. 32

Show Answer Answer:-A. 10
Explanation In this program, we are just printing the declared values. Output: $ g++ mac.cpp $ a.out 10

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

#include <iostream>

using namespace std;

#define MAX 10

int main()

{

int num;

num = ++MAX;

cout << num;

return 0;

}

A. 9
B. 10
C. 15
D. compile time error

Show Answer Answer:-D. compile time error
Explanation Macro Preprocessor only replaces occurance of macro symbol with macro symbol value, So we can’t increment the value.

Q 10. What is the other name of the macro?
A. executed directive
B. scripted directive
C. link directive
D. executed & link directive

Show Answer Answer:-B. scripted directive
Explanation When the compiler encounters a previously defined macro, it will take the result from that execution itself.

Leave a Reply

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

Author

quizsquestion@gmail.com

Related Posts

Python Questions and Answers – Exception Handling – 3

Python Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling – 3”. Q 1. What happens if the file is not...

Read out all

Python Questions and Answers – Exception Handling – 2

Python Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling – 2”. Q 1. The following Python code will result in...

Read out all

C++ Programming Questions and Answers – Exception Handling – 2

C++ Programming Multiple Choice Questions & Answers (MCQs) focuses on “Exception Handling – 2”. Q 1. Where should we place catch block...

Read out all

C++ Programming Questions and Answers – Exceptions That Are Not Errors

C++ MCQs (multiple choice questions) focuses on “Exceptions That Are Not Errors”. One shall practice these MCQs to improve their C++ programming...

Read out all

Python Questions and Answers – Encapsulation

Python Multiple Choice Questions & Answers (MCQs) focuses on “Encapsulation”. Q 1. Which of these is not a fundamental features of OOP?A....

Read out all

You cannot copy content of this page