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 is the correct way to receive user input in C++ and store it in a variable named 'name'?
cin >> name;
scanf name;
cout << name;
input name;
Which principle of OOP emphasizes hiding internal details and exposing only essential information?
Polymorphism
Abstraction
Encapsulation
Inheritance
Which of the following accesses the third element of an integer array named 'data'?
data.2
data[3]
data[2]
data.third
Why are pointers particularly useful when working with dynamic memory allocation?
Pointers help us avoid using loops and conditional statements.
Pointers allow us to directly access and manipulate memory addresses.
Pointers are required by the C++ syntax for dynamic memory allocation.
Pointers make our code run faster because they are low-level.
What C++ function can you use to find the length of a C-style string (character array)?
str_length()
length()
strlen()
size()
What is the output of the following C++ code snippet?
#include <iostream> int main() { int arr[5] = {10, 20, 30, 40, 50}; std::cout << arr[3]; return 0; }
40
10
30
50
What does the modulus operator (%) return?
The quotient of a division.
The product of two operands.
The sum of two operands.
The remainder of a division.
Which data type is used to store whole numbers without any decimal points?
string
double
float
int
If 'func' is a function that takes an integer and returns void, how would you call this function using a pointer 'ptr' to the function?
func(ptr, 5);
ptr(5);
&ptr(5);
*ptr(5);