What is the output of the following code snippet?
int i = 10; do { cout << i << " "; i--; } while (i > 10);
The loop will run infinitely
9 8 7 6 5 4 3 2 1 0
10 9 8 7 6 5 4 3 2 1
10
Which of the following is NOT a valid C++ function definition?
int sum(int a, int b) { return a + b; }
string greet(string name) { cout << "Hello, " << name << "!" << endl; }
void printMessage();
double calculateArea(double radius) { return 3.14 * radius * radius; }
Which data type is used to store whole numbers without any decimal points?
string
int
double
float
Which of the following accesses the third element of an integer array named 'data'?
data.2
data[2]
data[3]
data.third
What is a function signature in C++?
The comments and documentation associated with a function.
The function's name and the data types of its parameters.
The function's body (the code within the curly braces).
The value returned by the function.
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
0
50
100
Which principle of OOP emphasizes hiding internal details and exposing only essential information?
Polymorphism
Abstraction
Encapsulation
Inheritance
How do you declare a multi-dimensional array (specifically, a 2D array) in C++?
array matrix[3, 4];
int matrix(3)(4);
int matrix[3, 4];
int matrix[3][4];
What is the correct way to declare an integer array named 'numbers' with a size of 5 in C++?
int numbers(5);
numbers[5] as int;
int numbers[5];
array numbers[5];
What is the correct syntax to declare a pointer variable named 'ptr' that points to an integer?
int *ptr;
*int ptr;
ptr int;
int &ptr;