C++ Quiz
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 11% Most missed: “Which of the following is _not_ a consequence of declaring the member variable c…”

MCQs For LinkedIn Skill Assessments.

C++ Quiz
Time left 00:00
25 Questions

1. What would be the output of this code?
cpp
int i0=4, i1=6, i2=8;
int& nums[3]={i2,i0,i1};
std::cout<
2. What is an appropriate way of removing 'my_object' as shown below?
cpp
my_class *my_object = new my_class();
3. What is this expression equivalent to?
cpp
A->B
4. Which of the following is _not_ a consequence of declaring the member variable count of my_class as static?
cpp
class my_class {
public: static int count;
}
5. What is the purpose of a destructor?
6. Which statement is true when declaring the member variable 'count' as static?
cpp
class my_class{
public: static int count;
};
7. Which of the following STL classes is the best fit for implementing a phonebook? Suppose each entry contains a name and a phone number, with no duplicates, and you want to have lookup by name.
8. What is the output of this code?
cpp
int c=3; char d='A';
std::printf('c is %d and d is %c',c,d);
9. Which STL class is the best fit for implementing a collection of data that is always ordered so that the pop operation always gets the greatest of the elements? Suppose you are interested only in push and pop operations.
10. What does this part of a main.cpp file do?
cpp
#include 'library.h'
11. What's wrong with this definition when using a pre-C++11 compiler?
cpp
std::vector> thematrix;
12. Which of the following shows the contents of vector v1 and v2 after running this code?
cpp
std::vector v1{1,2,3},v2;
v2=v1;
v1.push_back(4);
v2.push_back(5);
13. What results from executing this code snippet?
cpp
int x=5, y=2;
if(x & y) {
/*_part A_*/
}
else {
/*_part B_*/
}
14. Which statement is true?
15. Which choice is the most reasonable implementation of the function std::mutex::lock() by using std::mutex::try_lock()?
16. What is the meaning of the three sections specified between parentheses in a for loop separated by semicolons?
17. What is true about the variable named 'ptr'?
cpp
void *ptr;
18. What's a benefit of declaring the parameter as a const reference instead of declaring it as a regular object?
cpp
int median(const my_array& a);
19. What is printed from this code?
cpp
int i = 0;
printf('%d', i++);
printf('%d', i--);
printf('%d', ++i);
printf('%d', --i);
20. What is a valid definition for the 'get_length' function, which returns the length of a null-terminated string?
21. When placed in a valid execution context, which statement will dynamically allocate memory from the heap for an integer of value 11?
22. Consider a class named 'complexNumber'. Which code will result in an equivalent object?
cpp
complexNumber(float real, float im)
: real_part(real),
im_part(im){}
23. Which choice is the correct declaration for the class named Dog, derived from the Animal class?
cpp
class Animal{
//....
}
24. What is this expression equivalent to?
cpp
A->B->C->D
25. What's the storage occupied by u1?
cpp
union {
unit16_t a;
unit32_t b;
int8_t c;
} u1;