C++ MCQ Questions and Answers – Part 5
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 statements is correct?
A The keyword “struct” is required in C and C++ while declaring a structure object.
B The keyword “struct” is not required in C but required in C++ when declaring a structure object.
C The keyword “struct” is not required in C++ but required in C when declaring a structure object.
D The keyword “struct” is not required in C and C++ when declaring a structure object.
2. Which of the following statements is correct?
A A structure cannot have a member function in C, but it is possible in C++.
B A structure cannot have a member function in C++ but it is possible in C.
C A structure cannot have a member function in C and C++.
D A structure can have a member function in C and in C++.
[st_adsense]
3. What happens if the following program is run in C and C++?
#include <stdio.h> void main() { printf("Hello World"); }
A Error in C and C++
B Warning in C and C++
C Error in C and success in C++
D Error in C++ and success in C
4. Which of the following statements correctly declares an array?
A int arr[10];
B int arr;
C arr{10};
D int [10]arr;
5. What is the index of the last element of an array with 5 elements?
A 5
B 4
C 0
D Defined by the programmer
[st_adsense]
6. What is the correct definition of an array?
A An array is a set of elements of the same type stored in contiguous memory locations
B An array is a set of elements
C An array is a set of elements of the same type stored in non-contiguous memory locations
D None of the above
7. Which of the following statements is correct about this pointer in C++?
A this pointer is passed as a hidden argument in all functions of a class.
B this pointer is passed as a hidden argument in all non-static functions of a class.
C this pointer is passed as a hidden argument in all static functions of a class.
D None of the above
8. What happens if the following program is run in C and C++?
#include <stdio.h> void f(void) { printf("Hello World!"); } void main() { f(); f(5); }
A Error in C and success in C++
B Error in C++ and success in C
C Error in C and C++
D Display “Hello World!” twice in C and C++
[st_adsense]
9. Which of the following features is not provided by C?
A Pointers
B Structures
C References
D Functions
10. Which of the following operators is used with a pointer to access members of a class?
A ~
B .
C ->
D !
[st_adsense]