reviewer for comp programming 1 final exam
reviewer for comp programming 1 final exam
4. What happens if a function declared with a return type (int) doesn't include a return statement?
a) The program will compile without errors.
b) The function returns a garbage value.
c) The program will terminate with an error.
5. Which type of error occurs when the syntax is incorrect in the code?
a) Syntax error
b) Logical error
c) Runtime error
8. When a program crashes due to a runtime error, what could be the primary cause?
a) Incorrect input handling or memory access.
b) An extra closing bracket }.
c) A missing #include directive.
11. Which data type would be used to store a floating-point number with decimals?
a) char
b) double
c) int
13. How many bytes does a double data type typically occupy in most compilers?
a) 8 bytes
b) 16 bytes
c) 4 bytes
17. What is the correct way to define a named constant for the value of Pi in C++?
a) const double Pi = 3.14;
b) double const Pi = 3.14;
c) Pi = 3.14;
18. Which of the following data types would be used to store a single character?
a) int
b) char
c) float
Operators (6 Questions)
26. Which of the following operators is used for conditional expressions in C++?
a) ?:
b) &&
c) &
31. What happens if you omit the break statement in a switch case in C++?
a) The program will throw an error.
b) The program will continue executing the next case.
c) The program will skip the switch statement.
40. Which of the following is a valid way to declare a variable with an automatic type deduction in
C++?
a) auto x = 10;
b) var x = 10;
c) type x = 10;
Here is the rearranged set of questions grouped logically for better flow:
40. Which of the following is a valid way to declare a variable with an automatic type deduction in
C++?
a) auto x = 10;
b) var x = 10;
c) type x = 10;
43. Which of the following should be included in the function definition, but not in the forward
declaration?
a) The function’s return type.
b) The function’s body.
c) The function’s name.
46. What is the result if a function is declared in a header file but not defined in any of the source files?
a) The program will compile with a warning.
b) The program will fail to compile.
c) The program will run with a runtime error.
48. Which of the following can be used to access a function inside a namespace?
a) namespace::function();
b) function(namespace);
c) namespace.function();
49. What happens when there are naming collisions between two namespaces?
a) The compiler automatically resolves the collision.
b) The program will compile, but only one function will be used.
c) The program will fail to compile due to ambiguity.