Which operator commonly tests equality?
A Assignment operator
B Increment operator
C Concatenation operator
D Equality comparison operator
Answer: D. Equality comparison operator. An equality operator compares two values and produces a Boolean result.
What does assignment usually do?
A Compares two expressions
B Repeats a statement
C Stores value in variable
D Declares a class
Answer: C. Stores value in variable. Assignment places a value into a named storage location.
What is the result of 7 mod 3?
A 2
B 3
C 1
D 4
Answer: C. 1. The remainder after dividing seven by three is one.
What does logical AND return true for?
A Either condition is true
B Both conditions are false
C Neither value is Boolean
D Both conditions are true
Answer: D. Both conditions are true. Logical AND is true only when both operands are true.
What does logical OR return true for?
A At least one condition true
B Only both conditions false
C Only equal numbers
D No conditions at all
Answer: A. At least one condition true. Logical OR is true when one or both operands are true.
What does logical NOT do?
A Adds two numbers
B Copies a string
C Ends a program
D Reverses a Boolean value
Answer: D. Reverses a Boolean value. Logical NOT changes true to false and false to true.
Which structure selects between alternatives?
A Sequence declaration
B Conditional statement
C Comment block
D Data type cast
Answer: B. Conditional statement. A conditional statement chooses which path to execute based on a condition.
What is the purpose of an if statement?
A Repeat code forever
B Declare a constant
C Run code when condition holds
D Define a file path
Answer: C. Run code when condition holds. An if statement executes its body when its condition is true.
What does an else branch handle?
A The alternative condition path
B The loop counter
C A function return type
D A memory address
Answer: A. The alternative condition path. An else branch provides code for when the preceding condition is false.
Which loop checks a condition before each iteration?
A Pretest loop
B Posttest loop
C Infinite loop only
D Recursive call
Answer: A. Pretest loop. A pretest loop checks its continuation condition before running each iteration.
Which loop guarantees one body execution?
A Pretest loop
B Conditional expression
C Posttest loop
D Event handler
Answer: C. Posttest loop. A posttest loop checks its condition after the body, so the body runs at least once.
What commonly controls a counted loop?
A Input output exception
B Initialization condition update
C Class object method
D Array string pointer
Answer: B. Initialization condition update. A counted loop typically has an initial value, continuation test, and update.
What is an off by one error?
A Wrong loop boundary
B Variable has wrong type
C Compiler cannot parse a token
D Program cannot open a file
Answer: A. Wrong loop boundary. Off by one errors come from a boundary or counting mistake.
What does break commonly do inside a loop?
A Skips one iteration
B Restarts the program
C Exits the nearest loop
D Declares a new variable
Answer: C. Exits the nearest loop. Break transfers control out of the nearest enclosing loop.
What does continue commonly do inside a loop?
A Skips to next iteration
B Exits every function
C Clears the loop condition
D Returns a stored value
Answer: A. Skips to next iteration. Continue skips the remaining body statements and begins the next iteration.
What is a nested loop?
A A loop inside another loop
B A loop without condition
C A function inside a variable
D A comment inside code
Answer: A. A loop inside another loop. Nested loops place one loop within the body of another.
What does operator precedence determine?
A How values are stored
B Where functions are declared
C Which files compile first
D Order operators are evaluated
Answer: D. Order operators are evaluated. Precedence rules establish which operators are evaluated first.
Why use parentheses in an expression?
A To allocate array memory
B To make grouping explicit
C To end a function
D To declare a Boolean
Answer: B. To make grouping explicit. Parentheses clarify intended grouping and can override default precedence.
What does short circuit evaluation mean?
A All operators run twice
B Expressions always run backward
C Values are converted to text
D Skip unneeded logic
Answer: D. Skip unneeded logic. With short circuiting, evaluation stops once a logical result is determined.
What does a function parameter represent?
A Value printed by a loop
B Global memory block
C Compiler output file
D Input name in function definition
Answer: D. Input name in function definition. A parameter is a named input in a function declaration or definition.
What is an argument in a function call?
A Function's source file
B Returned type declaration
C Value supplied to a parameter
D Loop's final condition
Answer: C. Value supplied to a parameter. An argument is the actual value supplied when calling a function.
What does return usually do?
A Repeats the current loop
B Sends a result to caller
C Creates a new module
D Reads keyboard input
Answer: B. Sends a result to caller. A return statement ends a function and may provide a result to its caller.
What is a function's return type?
A Type of its source file
B Type of value it produces
C Number of parameters only
D Scope of its variables
Answer: B. Type of value it produces. The return type describes the kind of value a function returns.
What is a local variable?
A Block scoped variable
B Variable shared by every program
C A fixed processor register
D Persistent file value
Answer: A. Block scoped variable. A local variable is accessible only within its defining scope.
What is a global variable?
A File scoped variable
B Variable declared outside local scopes
C Function's argument
D Temporary input character
Answer: B. Variable declared outside local scopes. A global variable is declared in a broader scope and may be accessible across functions.