0
0
Cprogramming~10 mins

Call stack behavior - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a function named 'foo'.

C
void [1]() {
    // function body
}
Drag options to blanks, or click blank then click option'
Afoo
Bbar
Cmain
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than 'foo'.
2fill in blank
medium

Complete the code to call the function 'foo' inside 'main'.

C
int main() {
    [1]();
    return 0;
}
Drag options to blanks, or click blank then click option'
Amain
Bfoo
Cstart
Dbar
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a function that is not defined or named differently.
3fill in blank
hard

Fix the error in the recursive function call to 'countdown'.

C
void countdown(int n) {
    if (n == 0) return;
    printf("%d\n", n);
    [1](n - 1);
}
Drag options to blanks, or click blank then click option'
Acountdownn
Bcount_down
Ccount
Dcountdown
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the function name in the recursive call.
4fill in blank
hard

Fill both blanks to create a function that prints numbers from 1 to n using recursion.

C
void print_numbers(int [1]) {
    if ([2] == 0) return;
    print_numbers([2] - 1);
    printf("%d\n", [2]);
}
Drag options to blanks, or click blank then click option'
Anum
Bn
Ccount
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for parameter and condition.
5fill in blank
hard

Fill all three blanks to create a recursive factorial function.

C
int factorial(int [1]) {
    if ([2] <= 1) return 1;
    return [2] * factorial([3] - 1);
}
Drag options to blanks, or click blank then click option'
Anum
Bn
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different variable names for the parameter and recursive call.