Q.1 Which control structure is used to execute a block of code repeatedly until a condition becomes false?
if
while
switch
break
Explanation - The while loop repeatedly executes a block of code as long as the condition is true.
Correct answer is: while
Q.2 Which keyword is used to exit a loop immediately in most programming languages?
continue
exit
break
stop
Explanation - The 'break' keyword terminates the nearest enclosing loop instantly.
Correct answer is: break
Q.3 What is the purpose of the 'continue' statement in a loop?
Exit the loop
Skip the current iteration
Stop the program
Repeat the loop infinitely
Explanation - 'continue' skips the rest of the current loop body and jumps to the next iteration.
Correct answer is: Skip the current iteration
Q.4 Which control structure is best for choosing one option out of many?
if-else chain
for loop
while loop
switch statement
Explanation - The switch statement is ideal for selecting one choice from many possible cases.
Correct answer is: switch statement
Q.5 What is the output of a function that does not have a return statement?
Error
0
null/None
Random value
Explanation - Functions without a return statement usually return a default value like null or None depending on the language.
Correct answer is: null/None
Q.6 Which keyword is used to define a function in Python?
func
function
def
lambda
Explanation - Python uses the 'def' keyword to define a named function.
Correct answer is: def
Q.7 Which keyword allows recursion in functions?
return
self
call
None
Explanation - Recursion works when a function calls itself and eventually returns to complete execution.
Correct answer is: return
Q.8 What is the default return type of a function in C if not specified?
int
void
float
double
Explanation - In older C standards, if the return type is omitted, it defaults to int.
Correct answer is: int
Q.9 What will the condition 'if (5)' evaluate to in C?
True
False
Error
Undefined
Explanation - Any non-zero value in C evaluates to true in conditional statements.
Correct answer is: True
Q.10 Which loop is guaranteed to execute at least once?
while
do-while
for
infinite while
Explanation - The do-while loop executes once before checking its condition.
Correct answer is: do-while
Q.11 Which of the following is not a control structure?
if
switch
loop
variable
Explanation - Variables store data, they are not control structures.
Correct answer is: variable
Q.12 Which keyword is used to return a value from a function?
return
output
yield
exit
Explanation - The 'return' keyword passes the result of a function back to the caller.
Correct answer is: return
Q.13 Which of these is a valid function name in most languages?
2sum
sum_
sum total
sum-total
Explanation - Function names must not start with digits or contain spaces, but underscores are allowed.
Correct answer is: sum_
Q.14 Which keyword in Java is used to define a function?
function
def
void
method
Explanation - In Java, functions (methods) are defined using return types like 'void' or 'int'.
Correct answer is: void
Q.15 Which function is the entry point of a C program?
start()
init()
main()
run()
Explanation - Execution of a C program begins with the main() function.
Correct answer is: main()
Q.16 Which of the following is true about recursion?
It never ends
It needs a base condition
It cannot return values
It is faster than loops always
Explanation - Recursion must have a base case to stop the repeated calls.
Correct answer is: It needs a base condition
Q.17 Which of the following is not a valid loop in C?
for
while
do-while
foreach
Explanation - C does not have a 'foreach' loop, unlike some modern languages.
Correct answer is: foreach
Q.18 Which keyword is used to call a function in Python?
call
invoke
def
none of these
Explanation - Functions in Python are called simply by their name followed by parentheses, no special keyword is needed.
Correct answer is: none of these
Q.19 Which of the following loops can have an infinite iteration if not handled properly?
for
while
do-while
all of the above
Explanation - Any loop can be infinite if its termination condition never becomes false.
Correct answer is: all of the above
Q.20 Which of the following is true about functions?
They reduce code reusability
They improve modularity
They increase redundancy
They always increase execution time
Explanation - Functions improve modularity by dividing programs into reusable blocks.
Correct answer is: They improve modularity
Q.21 What happens if a function calls itself without a base condition?
Program runs successfully
It will stop automatically
It causes infinite recursion
It optimizes itself
Explanation - Without a base case, recursion never stops, leading to stack overflow errors.
Correct answer is: It causes infinite recursion
Q.22 Which statement transfers program control to another part of the program?
goto
switch
case
if
Explanation - The 'goto' statement transfers control unconditionally to a labeled statement.
Correct answer is: goto
Q.23 Which of these is a benefit of using loops?
Reduces repetitive code
Increases code length
Prevents execution
Complicates logic
Explanation - Loops help execute repetitive tasks with less code.
Correct answer is: Reduces repetitive code
Q.24 Which of the following is a recursive mathematical function often used in programming?
Addition
Factorial
Multiplication
Subtraction
Explanation - The factorial function is a classic example of recursion in programming.
Correct answer is: Factorial
Q.25 In C, which loop syntax is correct?
for(i=0;i<10;i++)
for i in range(10)
loop(10)
while i<10:
Explanation - The correct C syntax for a for loop is 'for(initialization; condition; increment)'.
Correct answer is: for(i=0;i<10;i++)
