C++ MCQ Questions and Answers – Part 6
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 use of this pointer in C++?
A To access members of a class that have the same name as local variables in this scope.
B The pointer “this” points to the current object of the class.
C To access objects of another class.
D All the answers are true
[st_adsense]
2. What happens if we execute the following code in C and C++?
#include<stdio.h> struct STRUCT { int x; int f() { printf("Welcom to StackHowTo\n"); } }; int main() { struct STRUCT s; s.f(); return 0; }
A The program works correctly in C and C++ and displays “Welcom to StackHowTo” as output.
B The program returns an error in C but works perfectly in C++.
C The program returns an error in C++ but works perfectly in C.
D The program returns an error in C and C++
3. What does the following statement mean?
int (*fptr)(char*)
A Pointer to a pointer
B Pointer to an array of characters
C A pointer to a function taking a char * argument and returning an int
D Function taking a char * argument and returning a pointer to int
4. Which of the following will access the fifth element stored in an array?
A arr[4];
B arr[5];
C arr(5);
D [5]arr;
[st_adsense]
5. The operator used for de-referencing or indirection is ____
A &
B *
C ->
D <>
6. What is the output of the following C++ code?
#include <iostream> int main(int argc, char const *argv[]) { cout << "Welcom to StackHowTo"; return 0; }
A Welcom to StackHowTo
B Compilation error
C Runtime error
D No segmentation
7. Choose the right option :
string* a, b;
A a is a pointer to a string, b is a string.
B b is a pointer to a string, a is a string
C a and b are pointers of type String.
D None of the above
[st_adsense]
8. What is the value returned by is_int function?
bool is_int(12.54)
A False
B True
C 1
D None of the above
9. What is the value of “i”?
#include <iostream> using namespace std; int main() { int i; bool x = true; bool y = false; int a = 10; int b = 5; i = ((a | b) + (x + y)); cout << i; return 0; }
A 15
B 16
C 0
D True
10. Which of the following instructions is illegal?
A int *p = 0;
B int i; double* p = &i;
C string s, *p = 0;
D int *p;
[st_adsense]