Functions / Methods MCQs

Topic-wise practice questions for Programming (C++ / Java / Python). Test your knowledge, check solutions on demand, and pace your preparation.

Zero-leak answer engine • Rate-limited explanations
Practice in Timed Mode
Q1hard
Why will the following recursive function crash for sum(3)?

int sum(int n) {
    return n + sum(n - 1);
}
Q2easy
What is the output of this Python-like snippet?

def multiply(a, b):
    return a * b
print(multiply(b=3, a=2))
Q3medium
Trace the value of n in this "Pass-by-Value" example:

void doubleVal(int x) {
    x = x * 2;
}
int n = 10;
doubleVal(n);
print(n);
Q4easy
What is the output?

int x = 10;
void update() {
    x = 20;
}
update();
print(x);
Q5hard
Trace the value of result:

int calculate(int a, int b = 5) {
    return a + b;
}
int result = calculate(10);
Q6medium
What will be printed?

int x = 50;
void doSomething() {
    int x = 100;
}
doSomething();
print(x);
Q7medium
(Code-Tracing / Java Logic) What is the output of this snippet?

void changeList(List list) {
    list.add("B");
}
List myL = new ArrayList();
myL.add("A");
changeList(myL);
print(myL.size());
Q8easy
What does the void keyword indicate in a function signature?
Q9easy
In modern languages, what is a "Lambda" function?
Q10medium
A developer wants to return two different values (a result and an error code) from a single function in C++. What is the best modern approach?