C++ MCQ Questions with Answers – Part 13
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. Which of the following is the default return value of a function in C++?
A int
B char
C float
D void
2. What is the output of the following C++ code?
#include <iostream> using namespace std; void f(int x, int y) { x = 10; y = 5; } int main() { int x = 5; f(x, x); cout << x; return 0; }
A 5
B 10
C Compilation error.
D None of the above
3. What happens to a function defined in a class without any complex operation (like loop, etc.)?
A It becomes a virtual function of a class
B This becomes a default function of a class.
C This becomes an inline function of a class.
D The program displays an error
4. What is an inline function?
A function to increase the execution time of a program.
B A function called during compilation
C A function that is not checked for syntax errors
D A function whose semantic analysis is not verified
5. How many minimum functions must be present in a C++ program to run it?
A 0
B 1
C 2
D 3
6. What is the output of the following C++ code?
#include<iostream> using namespace std; int fun(int a = 0, int b = 0, int c) { return (a + b + c); } int main() { cout << fun(2); return 0; }
A 2
B 0
C Compilation error
D None of the above
7. What is the output of the following C++ code?
#include <iostream> using namespace std; int f(int=0, int = 0); int main() { cout << f(2); return 0; } int f(int a, int b) { return (a+b); }
A 2
B 0
C Compilation error
D None of the above
8. Which keyword do you use if you do not want to get a return value?
A static
B const
C void
D volatile
9. From which function does the execution of a C++ program start?
A Start() function
B new() function
C main() function
D All the answers are true
10. What is the value of x?
#include <iostream> using namespace std; void f(int &x) { x = 3; } int main() { int x = 2; f(x); cout << "The value of x is " << x; return 0; }
A 2
B 3
C Compilation error
D None of the above