Which loop is most suitable when you know the number of iterations in advance?
It depends on the specific situation.
for loop
do-while loop
while loop
What is the output of the following code snippet?
int arr[] = {10, 20, 30}; int *ptr = arr; cout << *(ptr + 2);
20
30
Invalid memory access
10
Which keyword is used to achieve inheritance in C++?
extends
implements
colon (:)
inherits
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[10] = "Hello";
char message[5] = "Hello";
char message[] = "Hello";
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 */
Which statement is used to skip the rest of the current iteration in a loop and jump to the next iteration?
goto
skip
break
continue
What is the correct way to declare a constant variable named 'PI' with the value 3.14159?
const float PI 3.14159;
constant PI = 3.14159;
#define PI = 3.14159
const float PI = 3.14159;
What is a potential danger of using pointers incorrectly?
It can lead to memory leaks if allocated memory is not freed.
It can make the code harder to debug due to the indirect way of accessing data.
It can cause segmentation faults if a pointer is dereferenced without a valid memory address.
All of the above
What is the purpose of the 'return' statement in a C++ function?
It prints the function's output to the console.
It terminates the function's execution and returns control to the calling function.
It declares a new variable within the function.
It marks a section of code for debugging purposes.
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; }
50
40