(GRADED A+).
Question 1
What is the primary difference between a literal and a variable?
A) A literal can change its value during runtime, while a variable is fixed.
B) A literal is a fixed value written directly in the code, whereas a variable is a named storage
location.
C) Variables are stored in ROM, while literals are stored in RAM.
D) Literals require a data type declaration, while variables do not.
E) There is no difference; the terms are interchangeable.
Correct Answer: B) A literal is a fixed value written directly in the code, whereas a variable
is a named storage location.
Rationale: In programming, a literal is data that is represented "as is," such as the number
5 or the string "Hello". A variable, however, is a container or an identifier that holds a
value. The value inside a variable can be updated or changed as the program executes, but
the literal itself remains a constant representation of data.
Question 2
Which of the following is the correct result of the expression 7 % 3?
A) 0
B) 1
C) 2
D) 2.33
E) 0.33
Correct Answer: B) 1
Rationale: The % operator is the modulo (or remainder) operator. When you divide 7 by 3,
3 goes into 7 twice (3 * 2 = 6), leaving a remainder of 1. Modulo is frequently used in
programming to check for even/odd numbers or to keep values within a specific range.
Question 3
What happens during "integer division" in most strictly typed languages?
A) The result is automatically rounded to the nearest whole number.
, 2
B) The program throws a runtime exception.
C) The fractional part is truncated (dropped), not rounded.
D) The result is automatically converted to a double or float.
E) The compiler generates a syntax error.
Correct Answer: C) The fractional part is truncated (dropped), not rounded.
Rationale: In languages like Java, C#, and C++, if you divide two integers (e.g., ), the
result is an integer. The mathematical answer is 2.5, but the system "truncates" the .5,
leaving only 2. This is a common source of logic errors in calculations involving averages or
percentages.
Question 4
Which data type would be most appropriate for storing a single character such as '$' or 'A'?
A) String
B) int
C) char
D) boolean
E) float
Correct Answer: C) char
Rationale: The 'char' (character) data type is specifically designed to hold a single 16-bit
Unicode character. While a String could hold a single character, a char is more memory-
efficient for single units of text. Strings are objects or arrays used for sequences of
characters.
Question 5
What is the value of x after the following code executes: int x = 10; x += 5 * 2;?
A) 30
B) 25
C) 20
D) 15
E) 40
, 3
Correct Answer: C) 20
Rationale: Following the order of operations (PEMDAS/BODMAS), the multiplication
occurs before the compound assignment. 5 * 2 = 10. Then, the expression becomes x = x +
10. Since x was 10, 10 + 10 = 20.
Question 6
Which of the following is a valid identifier (variable name) in most programming languages?
A) 1stPlace
B) total_Amount
C) class
D) my-Variable
E) $money!
Correct Answer: B) total_Amount
Rationale: Identifiers must start with a letter or an underscore (some languages allow $).
They cannot start with a digit (A is invalid), cannot contain hyphens or special punctuation
(D and E are invalid), and cannot be reserved keywords like 'class' (C is invalid).
Question 7
In a switch statement, what is the purpose of the break keyword?
A) To exit the entire program.
B) To restart the switch statement from the top.
C) To prevent "fall-through" into the next case.
D) To signal that the code is broken.
E) To return a value to the calling method.
Correct Answer: C) To prevent "fall-through" into the next case.
Rationale: Without a break statement, the program execution will continue into the
following case block even if the condition doesn't match. This "fall-through" behavior is
occasionally useful but is usually a logic error if unintentional.
Question 8
Which logical operator represents "Short-circuit AND"?
A) &
, 4
B) |
C) &&
D) ||
E) !
Correct Answer: C) &&
Rationale: The && operator is the short-circuit AND. If the first operand (the left side) is
false, the entire expression is guaranteed to be false, so the computer does not bother
evaluating the second operand. This is safer when the second operand might cause an error
(like division by zero).
Question 9
What is the purpose of the Scanner class in Java or Console.ReadLine() in C#?
A) To print text to the screen.
B) To perform mathematical calculations.
C) To receive input from the user.
D) To format decimal numbers.
E) To clear the console window.
Correct Answer: C) To receive input from the user.
Rationale: These tools are standard ways to make programs interactive. They allow the
program to pause and wait for the user to type data into the console, which is then assigned
to variables for processing.
Question 10
Which of the following represents a "Syntax Error"?
A) Dividing a number by zero.
B) Forgetting a semicolon at the end of a line.
C) Using the wrong formula for area.
D) An infinite loop.
E) Entering a string when the program expects an integer.
Correct Answer: B) Forgetting a semicolon at the end of a line.
Rationale: A syntax error occurs when the code violates the grammatical rules of the