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 code without functions
What is the output of this C code that repeats a task without using functions?
C
#include <stdio.h> int main() { int i; for(i = 1; i <= 3; i++) { printf("Hello, user!\n"); } for(i = 1; i <= 3; i++) { printf("Hello, user!\n"); } return 0; }
Attempts:
2 left
💡 Hint
Look at how many times the print statement runs in total.
✗ Incorrect
The code prints "Hello, user!" three times in the first loop and three times again in the second loop, totaling six times.
❓ Predict Output
intermediate2:00remaining
Output of code using functions
What is the output of this C code that uses a function to print a message multiple times?
C
#include <stdio.h> void greet() { printf("Hello, user!\n"); } int main() { int i; for(i = 1; i <= 3; i++) { greet(); } for(i = 1; i <= 3; i++) { greet(); } return 0; }
Attempts:
2 left
💡 Hint
The function greet() is called six times in total.
✗ Incorrect
The greet() function prints the message once. It is called three times in each loop, so the message prints six times total.
🧠 Conceptual
advanced1:30remaining
Why use functions instead of repeating code?
Which of the following is the main reason to use functions in C programming?
Attempts:
2 left
💡 Hint
Think about how functions help when you want to change something in many places.
✗ Incorrect
Functions help organize code by grouping repeated tasks. This avoids repeating code and makes it easier to update and maintain.
🔧 Debug
advanced1:30remaining
Identify the error in function usage
What error will this C code produce?
C
#include <stdio.h> void greet() { printf("Hello!\n"); } int main() { greet; return 0; }
Attempts:
2 left
💡 Hint
Check how functions are called in C.
✗ Incorrect
In C, functions must be called with parentheses. Writing 'greet;' is just a reference, not a call, causing a syntax error.
❓ Predict Output
expert2:00remaining
Output of nested function calls
What is the output of this C program with nested function calls?
C
#include <stdio.h> void printA() { printf("A"); } void printB() { printA(); printf("B"); } int main() { printB(); printf("C\n"); return 0; }
Attempts:
2 left
💡 Hint
Follow the order of function calls and prints step by step.
✗ Incorrect
printB() calls printA() first, which prints 'A'. Then printB() prints 'B'. Finally, main prints 'C' with a newline.