What is a variable in programming?
Correct answer:
A) A named storage location holding a value that can change
Explanation: A variable is a named location in memory that stores a value which can be read and modified during program execution.
What is a variable in programming?
Correct answer:
A) A named storage location holding a value that can change
Explanation: A variable is a named location in memory that stores a value which can be read and modified during program execution.
What is a constant?
Correct answer:
B) A named value that cannot be changed after it is set
Explanation: A constant holds a value assigned once that cannot be modified afterward, protecting values that should remain fixed such as tax rates or mathematical constants.
Which data type would best store a person's age in whole years?
Correct answer:
C) Integer
Explanation: An integer stores whole numbers without a fractional part, making it the appropriate type for a count of whole years.
Which data type stores true or false values?
Correct answer:
D) Boolean
Explanation: A Boolean data type holds only two possible values, true or false, and is used for conditions and logical decisions.
What is a string data type used for?
Correct answer:
A) Storing sequences of characters such as text
Explanation: A string stores a sequence of characters representing text, such as names, messages, or any textual data.
What does the assignment operator (=) do in most languages?
Correct answer:
B) Stores the value on the right into the variable on the left
Explanation: The single equals sign assigns the value of the right-hand expression to the variable on the left. Equality comparison typically uses == instead.
Which operator tests for equality in most programming languages?
Correct answer:
C) ==
Explanation: The double equals operator (==) compares two values and returns true if they are equal. A single equals sign performs assignment instead.
What does the modulus operator (%) return?
Correct answer:
D) The remainder after division
Explanation: The modulus operator returns the remainder left after integer division, commonly used to test divisibility or to cycle values within a range.
What is the result of 17 % 5?
Correct answer:
A) 2
Explanation: 17 divided by 5 equals 3 with a remainder of 2, so 17 % 5 evaluates to 2.
What does the logical AND operator require to evaluate as true?
Correct answer:
B) Both conditions must be true
Explanation: The logical AND operator returns true only when every operand evaluates to true. If any operand is false, the whole expression is false.
What does the logical OR operator require to evaluate as true?
Correct answer:
C) At least one condition must be true
Explanation: The logical OR operator returns true if at least one operand is true, and false only when every operand is false.
What does the logical NOT operator do?
Correct answer:
D) Reverses a Boolean value
Explanation: The NOT operator inverts a Boolean value, turning true into false and false into true.
What is the purpose of an if statement?
Correct answer:
A) Executing code only when a condition is true
Explanation: An if statement evaluates a condition and executes its block of code only when that condition is true, enabling conditional branching.
What does an else clause do?
Correct answer:
B) Provides code to run when the if condition is false
Explanation: The else clause specifies an alternative block of code that executes when the associated if condition evaluates to false.
What is the purpose of an else-if (elif) clause?
Correct answer:
C) Testing an additional condition when previous ones were false
Explanation: An else-if clause tests another condition when preceding conditions were false, allowing a chain of mutually exclusive alternatives.
What is a switch or case statement used for?
Correct answer:
D) Selecting among many branches based on one value
Explanation: A switch statement compares a single expression against multiple possible values and executes the matching branch, often clearer than a long if-else chain.
What is a loop in programming?
Correct answer:
A) A structure that repeats a block of code
Explanation: A loop repeatedly executes a block of code, either a set number of times or while a condition remains true, avoiding duplicated code.
When is a for loop most appropriate?
Correct answer:
B) When the number of iterations is known in advance
Explanation: A for loop is best when the iteration count is known ahead of time, such as processing every element in a collection of known size.
When is a while loop most appropriate?
Correct answer:
C) When repetition continues until a condition changes
Explanation: A while loop repeats as long as its condition remains true, suiting situations where the number of iterations depends on runtime conditions.
What is an infinite loop?
Correct answer:
D) A loop whose exit condition is never satisfied
Explanation: An infinite loop never terminates because its exit condition is never met, usually a bug caused by failing to update the controlling variable.
What does a break statement do inside a loop?
Correct answer:
A) Immediately exits the loop
Explanation: A break statement immediately terminates the enclosing loop and transfers control to the statement following it.
What does a continue statement do inside a loop?
Correct answer:
B) Skips the rest of the current iteration and proceeds to the next
Explanation: A continue statement skips the remaining statements in the current iteration and moves directly to the next iteration of the loop.
What is a nested loop?
Correct answer:
C) A loop placed inside another loop
Explanation: A nested loop is a loop contained within another loop. The inner loop completes all its iterations for each single iteration of the outer loop.
What is pseudocode?
Correct answer:
D) An informal description of an algorithm in plain structured language
Explanation: Pseudocode describes the logic of an algorithm using structured plain language, letting developers plan and communicate logic independently of any specific language syntax.
What is an algorithm?
Correct answer:
A) A finite sequence of well-defined steps to solve a problem
Explanation: An algorithm is a finite, ordered set of unambiguous steps that transforms input into a desired output, forming the logical basis of a program.
What is a flowchart used for?
Correct answer:
B) Visually representing the steps and decisions in a process
Explanation: A flowchart uses standard symbols to diagram the sequence of steps, decisions, and flow of control in a process or algorithm.
In a flowchart, what does a diamond shape typically represent?
Correct answer:
C) A decision point
Explanation: A diamond represents a decision where the flow branches based on a condition, typically with yes and no or true and false paths.
What is a syntax error?
Correct answer:
D) Code violating the language's grammatical rules
Explanation: A syntax error breaks the language's grammatical rules, such as a missing bracket or semicolon, and prevents the code from compiling or running.
What is a logic error?
Correct answer:
A) Code that runs but produces an incorrect result
Explanation: A logic error produces syntactically valid code that runs but yields incorrect results because the underlying reasoning or formula is wrong.
What is a runtime error?
Correct answer:
B) An error occurring while the program is executing
Explanation: A runtime error occurs during execution, such as dividing by zero or accessing an invalid array index, causing the program to fail or crash.
What is debugging?
Correct answer:
C) Finding and fixing defects in code
Explanation: Debugging is the systematic process of locating, diagnosing, and correcting defects so the program behaves as intended.
What is a breakpoint in a debugger?
Correct answer:
D) A marker pausing execution so state can be inspected
Explanation: A breakpoint instructs the debugger to pause execution at a specific line so the developer can examine variable values and program state.
What is the purpose of comments in source code?
Correct answer:
A) Explaining code to human readers without affecting execution
Explanation: Comments are ignored by the compiler or interpreter and exist to explain intent and reasoning to people reading or maintaining the code.
What is the difference between a compiler and an interpreter?
Correct answer:
B) A compiler translates the whole program before running; an interpreter executes line by line
Explanation: A compiler translates the entire source program into machine code before execution, while an interpreter reads and executes the source statement by statement at runtime.
What is variable scope?
Correct answer:
C) The region of a program where a variable is accessible
Explanation: Scope defines where in the program a variable can be referenced. Variables declared inside a block or function are typically not visible outside it.
What is a local variable?
Correct answer:
D) A variable accessible only within the function or block declaring it
Explanation: A local variable exists only within the function or block where it is declared and is destroyed when that block finishes executing.
What is a global variable?
Correct answer:
A) A variable accessible from anywhere in the program
Explanation: A global variable is declared outside any function and can be accessed throughout the program, though heavy use makes code harder to reason about and maintain.
What is type casting or type conversion?
Correct answer:
B) Converting a value from one data type to another
Explanation: Type casting converts a value from one data type to another, such as turning a numeric string into an integer for arithmetic operations.
What happens when an integer is divided by another integer in many languages?
Correct answer:
C) The fractional part may be truncated, yielding an integer
Explanation: Integer division in many languages discards the fractional portion, so 7 divided by 2 yields 3 rather than 3.5 unless a floating-point type is used.
What is operator precedence?
Correct answer:
D) The order in which operators are evaluated in an expression
Explanation: Operator precedence determines evaluation order in an expression, so multiplication is performed before addition unless parentheses change the grouping.
How can you control the order of evaluation in an expression?
Correct answer:
A) By using parentheses around sub-expressions
Explanation: Parentheses explicitly group sub-expressions and force them to be evaluated first, overriding default operator precedence.
What is user input in a program?
Correct answer:
B) Data supplied by the user during execution
Explanation: User input is data provided at runtime, typically through the keyboard, a file, or an interface, allowing programs to operate on varying data.
Why is input validation important?
Correct answer:
C) It prevents invalid or malicious data from causing errors or security issues
Explanation: Validating input ensures data meets expected format and range before use, preventing crashes, incorrect results, and security vulnerabilities such as injection attacks.
What is concatenation of strings?
Correct answer:
D) Joining two or more strings end to end
Explanation: Concatenation combines multiple strings into a single longer string, commonly using the plus operator or a dedicated function.
What does an index of 0 typically refer to in an array?
Correct answer:
A) The first element
Explanation: Most programming languages use zero-based indexing, so the first element of an array is at index 0 and the last is at index length minus one.
What is an off-by-one error?
Correct answer:
B) A mistake where a loop or index runs one iteration too many or too few
Explanation: An off-by-one error occurs when a boundary is miscalculated by one, such as looping to the array length instead of length minus one, often causing incorrect results or crashes.
What is initialization of a variable?
Correct answer:
C) Assigning it an initial value when declared
Explanation: Initialization assigns a starting value to a variable at declaration, preventing errors from using an undefined or unpredictable value.
What is an accumulator variable typically used for?
Correct answer:
D) Building up a running total across loop iterations
Explanation: An accumulator holds a running result, such as a sum or count, that is updated on each iteration of a loop.
What is a counter variable in a loop?
Correct answer:
A) A variable tracking how many iterations have occurred
Explanation: A counter tracks the number of iterations, typically incremented each pass and used to control loop termination or track occurrences.
What is the primary benefit of using meaningful variable names?
Correct answer:
B) Code becomes easier for humans to read and maintain
Explanation: Descriptive names communicate intent, making code easier to read, debug, and maintain. They have no effect on execution speed but substantially reduce human error.
If this exam is giving you a hard time, let us be your helping hand. Contact us, and we'll provide the assistance you need to pass and move forward.