Programming Fundamentals Quiz
Programming Fundamentals Quiz
---
4. Which of the following are valid reasons for a segmentation fault in C++?
Dereferencing a null pointer
Accessing an array out of bounds
Infinite recursion
All of the above
Answer: D) All of the above
6. Which of the following is true for switch statements in C++ when multiple
cases have the same label?
The program will compile and execute normally.
The program will compile but throw a runtime error.
The program will not compile due to duplicate labels.
The program will enter an infinite loop.
Answer: C) The program will not compile due to duplicate labels.
7. What will be the output of this code involving mixed unary and binary
operators?
int x = 5;
int y = --x * x++ + x;
cout << y;
24
25
26
27
Answer: C) 26
9. Which of the following errors will occur when dividing by zero in C++ with
an integer variable?
Syntax error
Compilation error
Runtime error
Undefined behavior
Answer: C) Runtime error
11. Which of the following conditions will lead to an infinite loop in C++?
Using while(1) without a break
Forgetting to increment a loop counter
Using for loop without an update expression
All of the above
Answer: D) All of the above
15. What happens if you use a float expression in a switch statement in C++?
The code will compile and run, treating float as int.
The code will not compile due to type incompatibility.
The program will throw a runtime error.
The program will run, but the switch will be ignored.
Answer: B) The code will not compile due to type incompatibility.
16. What is the output of the following program with mixed conditional
operators?
int x = 5, y = 10, z = 15;
int result = (x < y && y > z) ? y : z;
cout << result;
5
10
15
0
Answer: C) 15
20. Which of the following is true for both ++ and -- operators in C++?
They can only be used with integer types.
They can only be used as prefix operators.
They modify the operand directly.
They cannot be used within conditional expressions.
Answer: C) They modify the operand directly.