COSC 1436 Programming Fundamentals - Final Exam Review Questions & Answers
1. What is the output of the following C++ code snippet?
C++
int x = 5;
int y = 10;
cout << "The sum is: " << x + y << endl;
a) The sum is: 510
b) The sum is: 15
c) The sum is: x + y
d) Error
2. Which of the following is NOT a valid C++ data type?
a) int
b) double
c) char
d) string (Note: string is part of the standard library, not a built-in data type)
3. What is the purpose of the #include <iostream> preprocessor directive?
a) To define constants
b) To provide access to input/output stream objects like cout and cin
c) To declare variables
d) To create functions
4. Which loop is most suitable when you know the exact number of iterations in advance?
a) while loop
b) do-while loop
c) for loop
, d) switch statement
5. What is the value of x after the following code executes?
C++
int x = 10;
x += 5;
a) 5
b) 10
c) 15
d) 50
6. Which of the following is used to get a single character from the user?
a) cin >>
b) getline()
c) cin.get()
d) cin.ignore()
7. What is the purpose of the if statement in C++?
a) To repeat a block of code a certain number of times
b) To execute a block of code only if a certain condition is true
c) To define a function
d) To declare a variable
8. Which of the following is an example of a logical operator in C++?
a) +
b) -
c) *
d) && (AND operator)
9. What is the difference between = and == in C++?
, a) They are the same.
b) = is used for comparison, == is used for assignment
c) = is used for assignment, == is used for comparison
d) None of the above
10. What will be the output of the following C++ code?
C++
int num = 10;
if (num > 5) {
cout << "Greater than 5" << endl;
} else {
cout << "Less than or equal to 5" << endl;
}
a) Less than or equal to 5
b) Greater than 5
c) No output
d) Error
11. Which of the following is a valid way to declare and initialize an array in C++?
a) int myArray[];
b) int myArray[5] = {1, 2, 3, 4, 5};
c) int myArray = {1, 2, 3};
d) int myArray[3] = {1, 2, 3, 4};
12. What is the index of the first element in a C++ array?
a) 1
b) 0
c) -1
, d) It depends on the array size
13. Which of the following is used to pass an array to a function in C++?
a) The array name
b) The array size
c) Both the array name and size
d) None of the above
14. What is the output of the following C++ code snippet?
C++
int numbers[3] = {5, 10, 15};
cout << numbers[1];
a) 5
b) 10
c) 15
d) Error
15. Which of the following sorting algorithms has the best average-case time complexity?
a) Bubble sort
b) Insertion sort
c) Merge sort
d) Selection sort
16. What is the output of the following C++ code?
C++
int a = 5;
int b = 3;
int c = a / b;
cout << c;