
C++ test
Created on 23rd February 2025
Grade level: Higher Educationth grade
1 plays
30 Questions
No Description
Questions (30)
1. What is the output of the following code snippet: `std::cout << (5 + 2) * 3;`?
21
4 choice options
2. Which of the following is a valid way to declare a pointer in C++?
int* ptr;
4 choice options
3. What will happen if you attempt to dereference a null pointer?
It will cause a segmentation fault.
4 choice options
4. In C++, what does the 'new' keyword do?
It allocates memory for a variable at runtime.
4 choice options
5. Which of the following is a correct syntax for a class in C++?
class MyClass { int x; };
4 choice options
6. What is a destructor in C++?
A function called when an object is destroyed.
4 choice options
7. What is the purpose of the 'virtual' keyword in C++?
To allow dynamic binding of methods.
4 choice options
8. What does the 'const' keyword signify when used in a function parameter?
The parameter cannot be modified.
4 choice options
9. What is the output of the following code snippet: `std::vector<int> v = {1, 2, 3}; std::cout << v.size();`?
3
4 choice options
10. Which of the following is the correct way to include a standard library in C++?
#include <iostream>
4 choice options
11. What is the output of the following C++ code snippet: 'std::cout << (5 + 3) * 2;'?
16
4 choice options
12. Which of the following correctly defines a class in C++?
class MyClass {}
4 choice options
13. What is polymorphism in the context of C++ programming?
The ability to redefine methods in derived classes
4 choice options
14. In C++, what does the 'const' keyword signify when used in a function parameter?
The parameter cannot be modified
4 choice options
15. Which of the following statements about constructors in C++ is TRUE?
A class can have multiple constructors.
4 choice options
16. What is the purpose of the 'virtual' keyword in C++?
To enable method overriding
4 choice options
17. What is a reference variable in C++?
An alias for another variable
4 choice options
18. Which of the following is NOT a feature of object-oriented programming in C++?
Compilation
4 choice options
19. How do you allocate memory dynamically for an integer variable in C++?
int *ptr = new int;
4 choice options
20. What will be the output of the following code: 'std::cout << (true + false);'?
1
4 choice options
21. What is the output of the following C++ code? #include <iostream> using namespace std; int main() { int x = 5; cout << ++x; return 0; }
6
4 choice options
22. Which of the following is a correct way to define a function in C++?
int functionName() {}
4 choice options
23. What is the purpose of the 'virtual' keyword in C++?
To enable polymorphism in derived classes
4 choice options
24. Which operator is used to access members of a class in C++?
.
4 choice options
25. Consider the following code snippet. What does the 'delete' keyword do in C++? int* ptr = new int; delete ptr;
Frees the allocated memory for an integer
4 choice options
26. Which of the following statements about constructors is true?
They can be overloaded
4 choice options
27. In C++, what is the main purpose of the 'this' pointer?
To refer to the current object instance
4 choice options
28. What is the result of attempting to access an uninitialized pointer in C++?
The pointer will point to a random memory location
4 choice options
29. What is the purpose of the 'friend' keyword in C++?
To access private members of a class
4 choice options
30. Which data structure is used to implement a stack in C++?
Both Array and Linked List
4 choice options