Q1hard
Why will the following recursive function crash for sum(3)?
int sum(int n) {
return n + sum(n - 1);
}
Topic-wise practice questions for Programming (C++ / Java / Python). Test your knowledge, check solutions on demand, and pace your preparation.
int sum(int n) {
return n + sum(n - 1);
}
def multiply(a, b):
return a * b
print(multiply(b=3, a=2))
void doubleVal(int x) {
x = x * 2;
}
int n = 10;
doubleVal(n);
print(n);
int x = 10;
void update() {
x = 20;
}
update();
print(x);
int calculate(int a, int b = 5) {
return a + b;
}
int result = calculate(10);
int x = 50;
void doSomething() {
int x = 100;
}
doSomething();
print(x);
void changeList(List list) {
list.add("B");
}
List myL = new ArrayList();
myL.add("A");
changeList(myL);
print(myL.size());