Professional Documents
Culture Documents
New Microsoft Word Document (2)
New Microsoft Word Document (2)
New Microsoft Word Document (2)
Does the following function correctly calculate and return the sum
of all elements in an array?
int sumArray(int arr[], int size) {
int sum = 0;
for (int i = 0; i <= size; i++) {
sum += arr[i];
}
return sum;
}
Answer: False
Is it possible to initialize an array in C++ with a variable size
determined at runtime?
Answer: False
Can an array in C++ store elements of different data types?
Answer: False
Does the following code correctly check if the array arr is empty?
int arr[] = {1, 2, 3};
bool isEmpty = (sizeof(arr) / siz eof(arr[0])) == 0;
Answer: False
Can you use negative indices to access elements from the end of an
array in C++?
Answer: False
Is it possible to resize an array dynamically in C++ after it has been
declared?
Answer: False
Can you assign the contents of one array directly to another array
in C++ using the assignment operator (=)?
Answer: False
Control structure
Can the following C++ code result in a segmentation fault due to the goto
statement?
int data = 10;
goto skip;
data++;
skip:
cout << "Data: " << data << endl;
Answer: False
Will the following C++ code result in an infinite loop?
for (int i = 0; i != 10; i += 2) {
cout << i << " ";
}
Answer: false
Can the following C++ code result in a logic error due to the placement of
the increment operation?
int i = 1;
while (i <= 5) {
cout << i << " ";
i++;
}
Answer: False
Will the following C++ code result in an infinite loop if the input from the
user is zero?
int num;
cin >> num;
while (num != 0) {
cout << "You entered " << num << endl;
cin >> num;
}
Answer: False
Will the following C++ code result in an infinite loop when the user inputs a
negative number?
int num;
cin >> num;
while (num < 0) {
cout << "Please enter a non-negative number: ";
cin >> num;
}
Answer: False
Will the following C++ code result in an infinite loop when the initial value
of num is greater than 100?
int num = 150;
while (num > 100) {
cout << "High value: " << num << endl;
num - = 10;
}
Answer: False
Can the following C++ code cause a compile-time error due to the incorrect
use of the continue statement inside a switch within a for loop?
for (int i = 0; i < 5; i++) {
switch (i) {
case 2:
continue;
default:
cout << i << " ";
}
}
Answer: False
Will the following C++ code print "Even" for all integers in an array?
int numbers[] = {2, 4, 6, 7, 8};
for (int num : numbers) {
if (num % 2 == 0) {
cout << "Even" << endl;
}
}
Answer: False
Function true and false
Every function in C++ must return a value.
Answer: False
It is possible to define a function inside another function in C++.
Answer: False
Does the following function definition correctly allow calling the
function with no arguments in C++?
int add(int a = 5, int b) {
return a + b;
}
Answer: False
Does the following function definition correctly allow calling the
function with no arguments in C++?
int add(int a = 5, int b) {
return a + b;
}
Answer: False
Is the following function example demonstrating valid use of both
overloading and default parameters?
void display(int a) {
cout << "Integer: " << a << endl;
}
void display(double a = 3.14) {
cout << "Double: " << a << endl;
}
Answer: False
Is the following function declaration valid if you want to allow
calling the function without any arguments?
void greet(string msg = "Hello", string name) {
cout << msg << ", " << name << "!" << endl;
}
Answer: False
Will this function work correctly for all inputs to check if a number
is even?
bool isEven(int num) {
return num % 2;
}
Answer: False
Can the following function be used to return a reference to a local
variable?
int& dangerousFunction() {
int localValue = 100;
return localValue;
}
Answer: False