Challenge - 5 Problems
Function Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple function call
What is the output of this C program?
C
#include <stdio.h> int add(int a, int b); int main() { int result = add(3, 4); printf("%d\n", result); return 0; } int add(int a, int b) { return a + b; }
Attempts:
2 left
💡 Hint
Look at what the function 'add' returns and what is printed.
✗ Incorrect
The function 'add' returns the sum of its two parameters. Calling add(3,4) returns 7, which is printed.
❓ Predict Output
intermediate2:00remaining
Function declaration without definition
What happens when you compile and run this C code?
C
#include <stdio.h> int multiply(int x, int y); int main() { printf("%d\n", multiply(2, 3)); return 0; }
Attempts:
2 left
💡 Hint
The function is declared but not defined anywhere.
✗ Incorrect
The compiler knows the function signature but the linker cannot find the function's code, causing a linker error.
🔧 Debug
advanced2:00remaining
Identify the error in function definition
What error does this code produce?
C
#include <stdio.h> int square(int n) { return n * n; } int main() { printf("%d\n", square(5)); return 0; }
Attempts:
2 left
💡 Hint
Check punctuation at the end of the return line.
✗ Incorrect
The return statement now has a semicolon, so the code compiles and outputs 25.
❓ Predict Output
advanced2:00remaining
Function with pointer parameter output
What is the output of this program?
C
#include <stdio.h> void increment(int *p) { (*p)++; } int main() { int a = 10; increment(&a); printf("%d\n", a); return 0; }
Attempts:
2 left
💡 Hint
The function changes the value at the address passed.
✗ Incorrect
The function increments the value pointed to by p, so a becomes 11.
🧠 Conceptual
expert3:00remaining
Function declaration and definition order
Which option correctly explains why this code compiles and runs without errors?
C
#include <stdio.h> void greet(); int main() { greet(); return 0; } void greet() { printf("Hello!\n"); }
Attempts:
2 left
💡 Hint
Think about how the compiler processes declarations and definitions.
✗ Incorrect
The declaration before main tells the compiler the function signature, so the call in main is valid. The definition after main provides the actual code.