0
0
Cprogramming~20 mins

Function prototypes - Practice Problems & Coding Challenges

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

int add(int a, int b); // function prototype

int main() {
    int result = add(3, 4);
    printf("%d\n", result);
    return 0;
}

int add(int a, int b) {
    return a + b;
}
A0
BCompilation error
C34
D7
Attempts:
2 left
💡 Hint
Remember what the add function does and how prototypes help the compiler.
Predict Output
intermediate
2:00remaining
Effect of missing function prototype
What error or output occurs when calling a function without a prototype in C99 or later?
C
#include <stdio.h>

int main() {
    int x = multiply(2, 3);
    printf("%d\n", x);
    return 0;
}

int multiply(int a, int b) {
    return a * b;
}
ACompilation error: implicit declaration of function 'multiply'
B6
C0
DRuntime error
Attempts:
2 left
💡 Hint
Check if the compiler knows about multiply before main.
🔧 Debug
advanced
2:00remaining
Identify the prototype mismatch error
Which option shows a prototype that will cause a mismatch error with the function definition below?
C
int compute(int x, int y);

int compute(int a, float b) {
    return a + (int)b;
}
Aint compute(float x, float y);
Bint compute(int x, float y);
Cint compute(int x, int y);
Dint compute(int, int);
Attempts:
2 left
💡 Hint
Compare parameter types in prototype and definition carefully.
🧠 Conceptual
advanced
1:30remaining
Purpose of function prototypes
What is the main purpose of a function prototype in C?
ATo declare the function's return type and parameters before its use
BTo define the function's body
CTo allocate memory for the function
DTo call the function
Attempts:
2 left
💡 Hint
Think about what the compiler needs before a function is called.
Predict Output
expert
2:30remaining
Output with mismatched prototype and definition
What is the output of this program?
C
#include <stdio.h>

int foo(int a, int b); // prototype

int main() {
    int result = foo(5, 2);
    printf("%d\n", result);
    return 0;
}

int foo(int a, int b) {
    return a - b;
}
A7
B3
CCompilation error
DUndefined behavior
Attempts:
2 left
💡 Hint
Check if prototype and definition match and what foo returns.