Which C++ library provides functions for string manipulation, such as copying, concatenation, and comparison?
#include <string>
#include <iostream>
#include <cstring>
#include <array>
What is the primary purpose of a constructor in a C++ class?
To implement polymorphism
To free up memory when an object is destroyed
To initialize object members when an object is created
To define the class's interface
If 'ptr' points to the first element of an array, what does 'ptr + 1' point to?
The size of the array
The address of the array itself
The previous element in the array
The next element in the array
Which principle of OOP emphasizes hiding internal details and exposing only essential information?
Inheritance
Polymorphism
Encapsulation
Abstraction
What is the correct way to declare a multi-line comment in C++?
' This is a multi-line comment '
/* This is a multi-line comment */
// This is a multi-line comment
What is a pure virtual function in C++?
A function that automatically destroys an object
A function with no implementation in the base class, meant to be overridden by derived classes
A function that creates new data types
A function that can be called before an object is created
What is the correct way to declare a constant variable named 'PI' with the value 3.14159?
constant PI = 3.14159;
const float PI 3.14159;
#define PI = 3.14159
const float PI = 3.14159;
What will the following C++ code snippet print?
#include <iostream> void changeValue(int x) { x = 100; } int main() { int num = 50; changeValue(num); std::cout << num; return 0; }
None of the above
100
0
50
What does the 'protected' access specifier in C++ control?
Accessibility within the same class only
Accessibility within the same class and derived classes
Accessibility only within the same file
Accessibility from anywhere in the program
What will the following code snippet print?
int num = 10; while (num > 0) { num = num - 2; cout << num << " "; }
8 6 4 2 0
10 8 6 4 2
10 8 6 4 2 0
9 7 5 3 1