Test your knowledge of C++ programming concepts with this comprehensive quiz covering basic to advanced topics.
1. What is C++?
2. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
3. Which keyword is used to define a variable in C++?
4. What is the correct syntax to include the iostream library in C++?
5. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 5;
cout << x++;
return 0;
}
6. Which of the following is used to create a single-line comment in C++?
7. What is the correct way to declare a function in C++?
8. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 10;
if (x > 5) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
9. Which of the following is used to create a loop in C++?
10. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 0;
while (x < 3) {
cout << x;
x++;
}
return 0;
}
11. Which of the following is used to create an array in C++?
12. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int arr[3] = {1, 2, 3};
cout << arr[1];
return 0;
}
13. Which of the following is used to create a pointer in C++?
14. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 5;
int *ptr = &x;
cout << *ptr;
return 0;
}
15. Which of the following is used to create a reference in C++?
16. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 10;
int &ref = x;
ref = 20;
cout << x;
return 0;
}
17. Which of the following is used to create a class in C++?
18. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 10;
int y = 20;
cout << (x > y ? x : y);
return 0;
}
19. Which of the following is used to create an object in C++?
20. What is the output of the following code?
#include <iostream>
using namespace std;
int main() {
int x = 5;
int y = 2;
cout << x / y;
return 0;
}