MCQ

C++ MCQ Questions and Answers – Part 15

Multiple choice questions and answers (MCQs) on C++ to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as Variables, Operators, Conditional Statement, Functions, and more. This quiz will easily prepare anyone to pass their online test.
 

1. What is the output of the following C++ code?
#include <iostream>
using namespace std;
double & getVal()
{
	double v = 12.99;
	double &val = v;
	return val;
}
int main()
{
	double v = getVal();
	cout << "The value = " << v;
	return 0;
}

A 12

B 12.99

C Compilation error

D None of the above

B
The function returns 12.99.
 

 

 
 

2. Which header file is used to pass an unlimited number of arguments to a function?

A string.h

B stdlib.h

C stdarg.h

D None of the above

C
“stdarg.h” is a header file of the standard C library allowing functions to accept any number of arguments.

 

 

3. Which of the following statements allows you to overload a function in C++?

A Type

B Number of arguments

C Type and number of arguments

D None of the above

C
The type and number of arguments allows you to overload functions in C++, for example :

int myfunction(int);
float myfunction(float, float);

Here, the type and number of arguments are different.

 

 

4. What is the output of the following C++ code?
#include <iostream>
using namespace std;
void display(double  f)
{
	cout << f << endl;
}
void display(int i)
{
	cout << i << endl;
}
int main(void)
{
	display(3);
	display(28.99);
	return 0;
}

A 3

B 28.99

C Both A and B are true.

D None of the above
 

 
C

 

 

5. Which keyword is used to catch an exception in the code block?

A catch

B try

C throw

D None of the above

B
The try() statement is used to catch an exception in a block of code in C++.

 

 

6. What happens if the exception is not caught in the program?

A Error

B The program will be executed.

C The block of this code will not be executed.

D None of the above

A
When exceptions are not caught in a program, the program generates an error.

 

 

7. What is the maximum number of arguments or parameters that can be used in a function call?

A 64

B 256

C 255

D 254

B
C++ allows a maximum number of 256 arguments when calling a function.

 

 

8. Which keyword is used to define macros in C++?

A macro

B define

C #define

D None of the above

C
The keyword “#define” is used to define macros in C++.

 

 
 

9. What is the output of the following C++ code?
#include <iostream>
using namespace std;
int sum(int a, int b, int c)
{
	return a + b;
}
double sum(double a, double b, double c)
{
	return a + b;
}
int main()
{
	cout << sum(1, 2);
	cout << sum(1.5, 2.5);
	return 0;
}

A 3 4

B 4 3

C 3 4.5

D Compilation error

D
No function has a declaration similar to the functions called sum(int, int) and sum(double, double). Therefore, an error occurs.
 

 

 

10. Which symbol is used to declare preprocessor directives?

A $

B #

C %

D &

B
The # symbol is used to declare preprocessor directives.

 

 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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