What is the output of the following C++ code snippet?
int x = 5; if (x > 10) { x = 10; } else if (x < 0) { x = 0; } cout << x;
5
0
10
None of the above
What is the output of the following code snippet?
int i = 10; do { cout << i << " "; i--; } while (i > 10);
10 9 8 7 6 5 4 3 2 1
9 8 7 6 5 4 3 2 1 0
The loop will run infinitely
Which of these is NOT a benefit of using functions in programming?
Easier debugging and maintenance
Code reusability
Improved code organization
Increased memory usage
#include <iostream> int main() { int arr[5] = {10, 20, 30, 40, 50}; std::cout << arr[3]; return 0; }
50
30
40
What is the output of the following code snippet: cout << (5 > 3 && 10 < 20);?
cout << (5 > 3 && 10 < 20);
3
1
What is the correct way to receive user input in C++ and store it in a variable named 'name'?
scanf name;
cin >> name;
input name;
cout << name;
What is the purpose of the 'return' statement in a C++ function?
It marks a section of code for debugging purposes.
It declares a new variable within the function.
It terminates the function's execution and returns control to the calling function.
It prints the function's output to the console.
Which operator is used to access members of an object using a pointer to that object?
->
.
::
What is a pure virtual function in C++?
A function that can be called before an object is created
A function that automatically destroys an object
A function that creates new data types
A function with no implementation in the base class, meant to be overridden by derived classes
Which of the following is NOT a valid way to initialize a character array in C++?
char message[10] = {'H', 'e', 'l', 'l', 'o'};
char message[5] = "Hello";
char message[10] = "Hello";
char message[] = "Hello";