COS 201 PRACTICE MCQS
1. Which programming language was characterized by the use of **binary numbers** (0s and
1s) and was considered highly **machine dependent**?
A. Assembly Language
B. High-Level Language
C. Machine Language
D. FORTRAN
2. In the evolution of programming, the use of **mnemonics** to represent opcodes and
addresses first occurred in which language era?
A. Late 1940s
B. Early 1950s
C. Late 1950s
D. Early 1960s
3. A key problem associated with **Assembly Language** is that the level of abstraction is
relatively very low.
A. True
B. False
4. Which of the following languages is NOT listed in the course material as an example of a
**high-level language**?
A. FORTRAN
B. Python
C. BASIC
D. Hardwiring
5. Which stage of the Program Development Life Cycle (PDLC) involves **Algorithm
development**?
A. Problem Definition
B. Coding
C. Design
D. Testing and Debugging
6. The final phase in the Program Development Life Cycle (PDLC) is:
A. Documentation
B. Maintenance
C. Testing and Debugging
D. Coding
7. Which era saw the introduction of **algebraic expressions** as abstractions in writing
programs, leading to the development of languages like FORTRAN and C?
A. Early 1940s
B. Late 1940s
C. Early 1950s
D. Late 1950s
8. According to the language evolution diagram, which language directly preceded **Java**?
A. C++
B. Simula
C. Smalltalk
D. Modula 3
9. In the machine language example, the first 4 bits of an instruction are referred to as the:
A. Operand
B. Register name
C. Offset address
D. Opcode
10. Which programming language evolved directly from **ML**?
A. Prolog
B. Simula
C. Miranda
D. C++
[Link] programming paradigm that treats computation as the evaluation of mathematical
functions and avoids changing state is known as:
A. Declarative Programming
B. Logic Programming
C. Functional Programming
D. Scripting
12. Introduction to object-orientation as a technique for modelling computation is listed as part
of the course content. Which high-level language is introduced as a typical example of an
object-oriented language?
A. Python
B. Pascal
C. Java
D. FORTRAN
13. Which of the following is NOT listed as a basic object-oriented concept in the course
content?
A. Abstraction
B. Encapsulation
C. Virtualization
D. Classes
14. Which programming paradigm involves writing programs as sets of facts and rules?
A. Functional Programming
B. Logic Programming
C. Object-Oriented Programming
D. Sequential Programming
15. In Object-Oriented Programming, the concept of **polymorphism** is introduced as part of
the course contents.
A. True
B. False
16. Which C++ character set category includes mathematical, logical, and relational symbols?
A. Alphabets
B. Digits
C. Special symbols
D. White spaces
17. In C++, which escape sequence represents a **new line**?
A. \a
B. \t
C. \n
D. \v
18. Which of the following is an **invalid** C++ identifier based on the rules provided?
A. `_abc`
B. `y1`
C. `123x`
D. `sumRate`
19. C++ is a **case sensitive** language.
A. True
B. False
20. Program entities whose values **cannot be changed** during execution after initialization
are called:
A. Variables
B. Expressions
C. Literals
D. Constants
21. A **block statement** consists of zero or more statements enclosed in a pair of:
A. Parentheses ()
B. Square brackets [ ]
C. Angle brackets <>
D. Curly brackets {}
22. The C-style comment for multi-line documentation is embedded between:
A. /* and * /
B. / / and / /
C. <-- and -->
D. \ \ and \ \
23. The function from where C++ program execution begins is typically called:
A. `start()`
B. `main()`
C. `begin()`
D. `init()`
24. A simple statement in C++ must be terminated with a:
A. Comma (,)
B. Colon (:)
C. Semicolon (;)
D. Period (.)
25. Which control statement determines the execution path based on the truth or falsity of a
given condition?
A. Sequential statement
B. Selection statement
C. Repetition statement
D. Null statement
26. Which basic data type in C++ is listed as having a size of **8 bytes** and is sufficient for
storing 15 decimal digits?
A. `float`
B. `int`
C. `double`
D. `long`
27. The `char` data type in C++ stores a single character or ASCII values and is listed as having
a size of:
A. 0 bytes
B. 1 byte
C. 2 bytes
D. 4 bytes
28. The **`void`** data type represents:
A. Fractional numbers
B. True or false values
C. The size of an object
D. The absence of a type
29. [The type modifier that specifies a variable can **only** hold non-negative values,
extending its positive range, is:
A. `signed`
B. `short`
C. `unsigned`
D. `long`
30. The type modifier that **increases** the memory allocated for an integer or double type,
extending its range or precision, is:
A. `short`
B. `long`
C. `signed`
D. `unsigned`
31. Which derived data type is defined as **variables that store memory addresses**?
A. Arrays
B. Pointers
C. References
D. Function
32. Which user-defined data type serves as a **blueprint for creating objects, encapsulating data
and functions**?
A. `struct`
B. `union`
C. `enum`
D. `class`
33. The user-defined data type **`union`** allows different data types to share:
A. Different memory locations
B. The same memory location
C. Different data types
D. Named integer constants
34. The **`string`** type in C++ stores a sequence of characters and is considered a **built-in
type**.
A. True
B. False
35. The size listed for the `int` data type is:
A. 1 byte
B. 2 or 4 bytes
C. 4 or 8 bytes
D. 8 bytes
36. Which of the following is NOT an **Arithmetic Operator** in C++?
A. $+$
B. $\neq$
C. $\%$
D. $/$
37. In C++, the **Logical OR** operator is represented by:
A. &
B. ||
C. &&
D. !
38. [cite_start]Which of the following operators has **higher precedence**? [cite: 199]
A. Addition (+)
B. Subtraction (-)
C. Multiplication (*)
D. Assignment (=)
39. What is the result of the C++ expression `int x = 5 + 6 * 4;` due to operator precedence?
A. 44
B. 29
C. 26
D. 50
40. For operators of the same precedence, **Operator Associativity** determines:
A. Whether the operation is arithmetic or relational.
B. The type of operands used.
C. The order of evaluation (left-to-right or right-to-left).
D. The result data type.
41. Which control statement category includes the `if-else` and `switch` statements?
A. Sequential statements
B. Iteration statements
C. Selection statements
D. Other control statements
42. Which iteration statement (loop) is guaranteed to execute the statements at least once?
A. `while` loop
B. `for` loop
C. `do-while` loop
D. `for each` loop
43. What is the purpose of the **`break`** statement inside a loop?
A. Skips the rest of the current iteration.
B. Terminates the execution of the loop.
C. Starts the next iteration immediately.
D. Restarts the entire loop from the beginning.
44. The **`continue`** statement causes a loop to:
A. Terminate completely.
B. Skip the rest of the current iteration and move to the next.
C. Pause execution until a condition is met.
D. Execute the current iteration twice.
45. The `switch` statement in C++ is listed to work with all of the following data types EXCEPT:
A. `int`
B. `char`
C. `enum`
D. `float`
46. Which feature of an array is defined as **the number of different directions from which the
array can be viewed and its components referenced**?
A. Index
B. Size
C. Type
D. Dimension
47. Arrays adopt **zero indexing**. This means the index of the first component of an array is:
A. 1
B. 0
C. 2
D. Determined by the size
48. A **Linear Array** requires how many indices to reference its elements?
A. Zero
B. One
C. Two
D. Three
49. A **Vector** is a collection similar to an array, but it can:
A. Only store integers.
B. Only store built-in types.
C. Grow and shrink in length during program execution.
D. Only be one-dimensional.
50. In the context of a **Vector**, the **capacity()** member function returns the number of
elements for which there is:
A. Data defined
B. Memory allocation
C. A specified base type
D. An index greater than zero
ANSWER KEY
1. C
2. B
3. A
4. D
5. C
6. B
7. D
8. C
9. D
10. C
11. C
12. C
13. C
14. B
15. A
16. C
17. C
18. C
19. A
20. D
21. D
22. A
23. B
24. C
25. B
26. C
27. B
28. D
29. C
30. B
31. B
32. D
33. B
34. B
35. B
36. B
37. B
38. C
39. B
40. C
41. C
42. C
43. B
44. B
45. D
46. D
47. B
48. B
49. C
50. B
What's the output of the following code:
int x = 1;
while (x < 3) {
cout << x;
x++;
}
Answer: The loop runs when x=1 (output 1) and when x=2 (output 2). When x becomes 3,
the condition x < 3 is false and the loop ends. Output: 12.
for (int i = 0; i < 5; i++) {
if (i == 3) continue;
cout << i;
}
Answer: When i=3, the continue statement is executed, skipping the cout << i; for that
iteration. Output: 0124
int x = 10, y = 3;
int result = x % y;
Answer: The modulus operator (%) returns the remainder. 10 \ 3 = 3 with a remainder of
1.
int x = 5, y = 3, z = 6;
x = y = z;
Answer: Assignment operators are right-to-left associative. It is evaluated as y = z (y
becomes 6), then x = y (x becomes 6). Thus, y is 6
C++ OPERATOR OUTPUT MCQS
1. What is the final value of `result`?
```cpp
int a = 11, b = 3;
int result = a / b * 2;
```
A. 6
B. 7
C. 5
D. 8
2. What is the final value of `x`?
```cpp
int x = 10;
x = x++ + 5;
```
A. 15
B. 16
C. 10
D. 11
3. What is the value of `y` after the expression?
```cpp
int x = 5;
int y = --x * 2;
```
A. 10
B. 8
C. 12
D. 4
4. What is the boolean result (True/False or 1/0) of the expression?
```cpp
int p = 10, q = 20;
bool result = (p > 5) && (q == 15);
```
A. True (1)
B. False (0)
5. What is the final value of `c`?
```cpp
int a = 1, b = 0;
int c = a || b;
```
A. 0
B. 1
C. Undefined
D. 2
6. What is the final value of `y`?
```cpp
int x = 6;
int y = (x += 2) * x;
```
A. 48
B. 36
C. 64
D. 80
7. What is the final value of `result`?
```cpp
int num = 10;
int result = (num != 10) || (num >= 10);
```
A. 0
B. 1
C. True
D. False
8. What is the output of the expression using the **bitwise AND** operator?
```cpp
int x = 5; // Binary 0101
int y = 3; // Binary 0011
int result = x & y;
cout << result;
```
A. 7
B. 1
C. 5
D. 3
9. What is the value of `k`?
```cpp
int i = 1, j = 2;
int k = j + i++;
```
A. 3
B. 4
C. 2
D. 5
10. What is the final value of `a`?
```cpp
int a = 15;
a >>= 2; // Bitwise right shift compound assignment
```
A. 3
B. 7
C. 4
D. 0
11. What is the result of the expression involving operator precedence?
```cpp
int result = 20 - 4 / 2 * 3;
```
A. 14
B. 18
C. 27
D. 9
12. What is the value of `b` after the expression?
```cpp
int a = 7;
int b = a > 5 ? 10 : 20; // Ternary operator
```
A. 7
B. 10
C. 20
D. Undefined
13. What is the boolean result (1/0) of the expression?
```cpp
int x = 8, y = 8;
int result = (x == y) != (x > y);
```
A. 0
B. 1
14. What is the output of the expression using the **Bitwise OR** operator?
```cpp
int a = 6; // Binary 0110
int b = 9; // Binary 1001
int result = a | b;
cout << result;
```
A. 15
B. 3
C. 0
D. 12
15. What is the final value of `count`?
```cpp
int count = 1;
count *= 5 + 3; // Compound assignment
```
A. 8
B. 15
C. 24
D. 5
16. What is the final value of `y`?
```cpp
int x = 10;
int y = ! (x < 5); // Logical NOT operator
```
A. 0
B. 1
C. 5
D. Undefined
17. What is the value of `c`? (Assume short-circuiting applies)
```cpp
int a = 5;
bool c = (a++ > 5) && (a == 6);
```
A. True (1)
B. False (0)
18. What is the final value of `p`?
```cpp
int p = 5;
p = 3 * (p % 2);
```
A. 3
B. 6
C. 5
D. 1
C++ Operator Output MCQs Answer Key
1. A - 11 / 3 (integer division) is 3. Then 3 * 2 = 6
2. A - Post-increment (`x++`): The original value of x (10) is used in the expression first,
then x is incremented. 10 + 5 = 15. x is now 11, but the result is 15.
3. B - Pre-decrement (`--x`): x is decremented first (x becomes 4), then the new value is
used in the expression. 4 * 2 = 8.
4. B - (10 > 5) is True (1). (20 == 15) is False (0). True && False is False (0).
5. B - The logical OR operator (`||`) returns 1 if either operand is non-zero. 1 || 0 is 1
6. C - Compound assignment (`+=`): x becomes 6 + 2 = 8. Then y is calculated: 8 * 8 = 64.
7. B - (10 != 10) is False (0). (10 >= 10) is True (1). False || True is True (1).
8. B - Binary: 5 = 0101, 3 = 0011. Bitwise AND ( & ) gives 0001, which is 1.
9. A - Post-increment (`i++`): The original value of i (1) is used in the expression first. k =
2 + 1 = 3. i is then incremented to 2. k is e.
10.A - Right Shift (`>>= 2`): Shifts 15 (Binary 1111) two places to the right. 1111 to 0011.
0011 is 3. (Equivalent to 15 / 2² = 15 / 4 = 3 in integer arithmetic).
11.A - Precedence: /and * are equal (left-to-right). 1st: 4 / 2 = 2, then 2 * 3 = 6, finally 20 -
6 = 14.
12.B - Ternary Operator: 7 > 5 is True. So the result is the expression after the ? (10). b is
10.
13.B - (8 == 8) is True (1). (8 > 8) is False (0). The expression is: 1 \ 0, which is True (1).
14.A - Binary: 6 = 0110, 9 = 1001. Bitwise OR ( | ) gives 1111, which is 15.
15.A - Compound assignment: Parentheses are evaluated first. 5 + 3 = 8. Then count = count
* 8 is 1 * 8 = 8.
16.B - (10 < 5) is False (0). Logical NOT ( ! ) flips the boolean result: !0 is 1.
17.B - Short-circuiting: (a++ > 5) is evaluated first. a++ > 5 uses a=5 for the comparison (5
> 5 is False). Since the left side of the `&&` is False, the entire expression is False, and
the right side (a == 6) is never evaluated. `c` is **False (0). a becomes 6 due to the a++
side effect.
18.A - Modulus: 5 % 2 is 1 (the remainder of 5 \ 2). p = 3 * 1 = 3