0
0
Cprogramming~20 mins

Function calling - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Function Calling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of nested function calls
What is the output of this C program when run?
C
#include <stdio.h>

int add(int a, int b) {
    return a + b;
}

int multiply(int x, int y) {
    return x * y;
}

int main() {
    int result = multiply(add(2, 3), add(4, 1));
    printf("%d\n", result);
    return 0;
}
A15
B20
C25
D10
Attempts:
2 left
💡 Hint
Remember to evaluate the inner add() calls before multiply().
Predict Output
intermediate
2:00remaining
Function call with pointer argument
What will be printed by this C program?
C
#include <stdio.h>

void update(int *p) {
    *p = *p + 10;
}

int main() {
    int val = 5;
    update(&val);
    printf("%d\n", val);
    return 0;
}
A15
B10
C5
D0
Attempts:
2 left
💡 Hint
The function changes the value at the pointer's address.
Predict Output
advanced
2:00remaining
Output of recursive function call
What is the output of this C program?
C
#include <stdio.h>

int factorial(int n) {
    if (n == 0) return 1;
    else return n * factorial(n - 1);
}

int main() {
    printf("%d\n", factorial(4));
    return 0;
}
A120
B10
C16
D24
Attempts:
2 left
💡 Hint
Factorial of 4 is 4*3*2*1.
Predict Output
advanced
2:00remaining
Output with function pointer call
What does this C program print?
C
#include <stdio.h>

int square(int x) {
    return x * x;
}

int main() {
    int (*func_ptr)(int) = square;
    int val = 3;
    printf("%d\n", func_ptr(val));
    return 0;
}
A9
B6
C3
D0
Attempts:
2 left
💡 Hint
Function pointers can be called like normal functions.
Predict Output
expert
2:00remaining
Output of function call with side effects and order
What is the output of this C program?
C
#include <stdio.h>

int f(int *x) {
    (*x)++;
    return *x;
}

int main() {
    int a = 5;
    int result = f(&a) + f(&a);
    printf("%d\n", result);
    return 0;
}
A12
B13
C11
D10
Attempts:
2 left
💡 Hint
The order of evaluation of function arguments is unspecified in C.