If 'ptr' is a pointer to an integer variable 'num', how would you access the value stored in 'num' using 'ptr'?
&ptr
num
ptr
*ptr
How do you declare a multi-dimensional array (specifically, a 2D array) in C++?
int matrix(3)(4);
int matrix[3, 4];
array matrix[3, 4];
int matrix[3][4];
What is the output of the following code snippet?
int arr[] = {10, 20, 30}; int *ptr = arr; cout << *(ptr + 2);
20
30
10
Invalid memory access
Which operator is used to access members of an object using a pointer to that object?
.
->
::
Which of the following is NOT a valid C++ function definition?
string greet(string name) { cout << "Hello, " << name << "!" << endl; }
void printMessage();
double calculateArea(double radius) { return 3.14 * radius * radius; }
int sum(int a, int b) { return a + b; }
Which of the following accesses the third element of an integer array named 'data'?
data.third
data[3]
data.2
data[2]
Which principle of OOP emphasizes hiding internal details and exposing only essential information?
Polymorphism
Encapsulation
Inheritance
Abstraction
Why are pointers particularly useful when working with dynamic memory allocation?
Pointers are required by the C++ syntax for dynamic memory allocation.
Pointers help us avoid using loops and conditional statements.
Pointers allow us to directly access and manipulate memory addresses.
Pointers make our code run faster because they are low-level.
What is a pure virtual function in C++?
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 automatically destroys an object
A function that can be called before an object is created
How do you declare a variable named 'age' of integer type?
int age;
declare age as integer;
variable age: int;
age as int;