c-quiz

Dive into the world of C++ programming with this comprehensive quiz designed to test your knowledge and skills. From basic syntax to advanced concepts, each question will challenge your understanding and help you gauge your proficiency in this powerful programming language. Good luck and enjoy the challenge!
We recommend that you do not leave the page that you are taking this quiz in. Stay honest 🙂
C++ Quiz
0% Complete
1 of 17
1. What is the correct syntax to declare a variable in C++?
Choose the correct syntax for declaring a variable.

C++ Quiz Questions Overview

1. What is the correct syntax to declare a variable in C++?

int variableName;
variableName int;
int variableName()
variableName int;

2. Which of the following is a correct comment in C++?

// This is a comment
/* This is a comment */
# This is a comment
Both // This is a comment and /* This is a comment */

3. Which of the following is used to create an object in C++?

ClassName objectName;
objectName ClassName;
ClassName objectName()
objectName = new ClassName();

4. What is the output of the following code: int x = 5; cout << x++;?

5
6
0
Compilation error

5. Which of the following is a correct way to allocate memory dynamically in C++?

int *ptr = new int;
int ptr = new int;
int *ptr = malloc(sizeof(int));
int ptr = malloc(sizeof(int));

6. What is the purpose of a destructor in C++?

To initialize an object
To destroy an object
To allocate memory
To deallocate memory

7. Which of the following is a valid way to define a function in C++?

void functionName() {}
functionName void() {}
void functionName {}
functionName() void {}

8. What is the output of the following code: int x = 10; int y = x << 1; cout << y;?

20
5
10
0

9. Which of the following is a feature of object-oriented programming in C++?

Encapsulation
Recursion
Pointers
Templates

10. What is the purpose of the ‘this’ pointer in C++?

To refer to the current object
To refer to the base class
To refer to a global variable
To refer to a static variable

11. Which of the following is a correct way to handle exceptions in C++?

try { /* code */ } catch (Exception e) { /* code */ }
try { /* code */ } except (Exception e) { /* code */ }
try { /* code */ } catch { /* code */ }
try { /* code */ } catch (…) { /* code */ }

12. Which of the following is a correct way to define a class in C++?

class ClassName { /* members */ };
ClassName class { /* members */ };
class ClassName { /* members */ }
ClassName { /* members */ };

13. What is the output of the following code: int x = 5; int y = 10; cout << (x > y ? x : y);?

5
10
0
Compilation error

14. Which of the following is a correct way to create a pointer in C++?

int *ptr;
ptr int*;
int ptr*;
int* ptr;

15. What is the purpose of the ‘virtual’ keyword in C++?

To create a virtual function
To create a virtual class
To create a virtual object
To create a virtual variable

16. Which of the following is a correct way to include a header file in C++?

#include
#include header.h
include
include header.h

17. What is the output of the following code: int arr[] = {1, 2, 3}; cout << arr[1];?

1
2
3
Compilation error
We recommend that you do not leave the page that you are taking this quiz in. Stay honest 🙂
We have chosen the next challenge for you. Take the next test:

Can Your Friends Do Better Than You in This Quiz?

Share this quiz with your friends and compare results.

Was this page helpful?