0% found this document useful (0 votes)
21 views

reviewer for comp programming 1 final exam

Uploaded by

Duane Luy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

reviewer for comp programming 1 final exam

Uploaded by

Duane Luy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Value-Returning Functions (4 Questions)

1. What is the purpose of the return statement in a function?


a) It exits the function without returning a value.
b) It returns a value to the calling function and exits.
c) It pauses the function until an external condition is met.

2. Which of the following is not a value-returning function in C++?


a) void calculate() { }
b) int calculate() { return 5; }
c) double calculate() { return 3.14; }

3. Which of the following is a valid function prototype in C++?


a) function void calculate();
b) int calculate(int x);
c) void calculate() { }

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.

Debugging C++ Programs (4 Questions)

5. Which type of error occurs when the syntax is incorrect in the code?
a) Syntax error
b) Logical error
c) Runtime error

6. What is the first step in the debugging process?


a) Rewriting the entire program.
b) Identifying where the error occurs.
c) Adding more return statements.

7. Which of the following debugging techniques helps isolate a logical error?


a) Using print statements or a debugger.
b) Adding new code lines.
c) Changing variable names.

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.

Fundamental Data Types (6 Questions)

9. Which of the following is an integer data type in C++?


a) int
b) double
c) bool

10. What does the sizeof operator do in C++?


a) Returns the size of a variable in bytes.
b) Returns the variable's value.
c) Declares the type of the variable.

11. Which data type would be used to store a floating-point number with decimals?
a) char
b) double
c) int

12. Which of the following is a valid signed integer type in C++?


a) unsigned int
b) long int
c) size_t

13. How many bytes does a double data type typically occupy in most compilers?
a) 8 bytes
b) 16 bytes
c) 4 bytes

14. What is the value of sizeof(bool) on most compilers?


a) 1 byte
b) 2 bytes
c) 4 bytes

Constants and Strings (6 Questions)

15. Which of the following defines a constant variable in C++?


a) const int x = 10;
b) int const x = 10;
c) x = 10;

16. Which of the following is a valid string literal in C++?


a) "Hello"
b) 'Hello'
c) Hello

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

19. What does the std::string class store in C++?


a) A single character.
b) A collection of characters.
c) An array of integers.

20. Which function is used to concatenate two strings in C++?


a) append()
b) strcat()
c) +

Operators (6 Questions)

21. Which operator is used to calculate the remainder of a division in C++?


a) %
b) +
c) *

22. What does the increment operator (++) do?


a) Increases the value of a variable by 1.
b) Decreases the value of a variable by 1.
c) Multiplies the value of a variable by 2.

23. What is the result of 10 / 3 in C++ using integer division?


a) 3
b) 3.33
c) 3.0

24. Which of the following operators has the highest precedence?


a) *
b) +
c) &&

25. What is the result of the following expression: 3 * 2 + 4 % 2?


a) 8
b) 6
c) 10

26. Which of the following operators is used for conditional expressions in C++?
a) ?:
b) &&
c) &

Control Flow (8 Questions)

27. Which keyword is used to exit a loop in C++?


a) return
b) continue
c) break

28. Which of the following is a correct syntax for an if statement in C++?


a) if (x > 10) { }
b) if x > 10 { }
c) if x > 10 then { }

29. Which loop will always execute at least once in C++?


a) while
b) for
c) do-while

30. What is the correct syntax for a for loop in C++?


a) for (int i = 0; i < 10; i++) { }
b) for i = 0 to 10 { }
c) for (int i; i < 10; i++) { }

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.

32. In which case will a goto statement be appropriate in C++?


a) To repeat a section of code multiple times.
b) To handle exception cases in loops.
c) To jump to a specific part of the program.

33. What is the effect of the continue statement in loops?


a) It stops the current loop and exits it.
b) It skips the current iteration and proceeds to the next one.
c) It breaks the loop entirely.
34. Which control structure can be used for multi-way branching in C++?
a) if-else
b) switch
c) for

Type Conversion, Type Aliases, and Type Deduction (6 Questions)

35. What is implicit type conversion in C++?


a) The automatic conversion of one data type to another.
b) The manual conversion of one data type to another.
c) A runtime error when the types are mismatched.

36. Which of the following is an example of type aliasing in C++?


a) typedef int Integer;
b) int x = 10;
c) float y = 3.14;

37. What happens during numeric conversion from int to double?


a) The value is truncated.
b) The value is automatically promoted to the double type.
c) The value will be rounded off.

38. What is a narrowing conversion in C++?


a) Converting a larger data type to a smaller one.
b) Converting a smaller data type to a larger one.
c) Converting an integer to a string.

39. What does decltype do in C++?


a) It determines the type of an expression.
b) It defines a new type for a variable.
c) It casts a variable to a different type.

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:

Automatic Type Deduction (1 Question)

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;

Forward Declarations and Definitions (3 Questions)

41. Which of the following is a forward declaration of a function in C++?


a) void calculate();
b) void calculate() { }
c) calculate();
42. Why are forward declarations useful in C++?
a) They allow the compiler to recognize the function before its definition.
b) They define the function's body.
c) They avoid using the #include directive.

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.

Programs with Multiple Code Files (3 Questions)

44. What is the purpose of a header file in C++?


a) To store function declarations and constants.
b) To store the program's main function.
c) To define global variables.

45. How are multiple source files combined in C++?


a) Through the use of #include.
b) By defining multiple main() functions.
c) By linking object files during compilation.

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.

Naming Collisions and Namespaces (3 Questions)

47. What is the purpose of namespaces in C++?


a) To avoid naming collisions by grouping related code.
b) To declare global variables.
c) To define constant values.

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.

Introduction to the Preprocessor (1 Question)

50. What is the role of the preprocessor in C++?


a) It executes the program code before compilation.
b) It replaces macros and includes files before compilation.
c) It stores data during runtime.

You might also like