Bird
Raised Fist0
Cprogramming~10 mins

Function calling - Interactive Code Practice

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

Complete the code to call the function greet.

C
#include <stdio.h>

void greet() {
    printf("Hello!\n");
}

int main() {
    [1];
    return 0;
}
Drag options to blanks, or click blank then click option'
Agreet()
Bgreet
Cgreet[]
Dcall greet()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses when calling the function.
Using incorrect syntax like brackets or keywords.
2fill in blank
medium

Complete the code to call the function add with arguments 5 and 3.

C
#include <stdio.h>

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

int main() {
    int result = [1];
    printf("%d\n", result);
    return 0;
}
Drag options to blanks, or click blank then click option'
Aadd{5, 3}
Badd[5, 3]
Cadd 5, 3
Dadd(5, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of parentheses for arguments.
Using brackets or braces instead of parentheses.
3fill in blank
hard

Fix the error in the function call to multiply with arguments 4 and 7.

C
#include <stdio.h>

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

int main() {
    int product = multiply[1];
    printf("%d\n", product);
    return 0;
}
Drag options to blanks, or click blank then click option'
A(4, 7)
B[4, 7]
C{4, 7}
D4, 7
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Omitting parentheses entirely.
4fill in blank
hard

Fill both blanks to call the function divide with arguments 10 and 2, and store the result in result.

C
#include <stdio.h>

double divide(double a, double b) {
    return a / b;
}

int main() {
    double [1] = [2];
    printf("%.2f\n", result);
    return 0;
}
Drag options to blanks, or click blank then click option'
Aresult
Bdivide(10, 2)
Cdivide(2, 10)
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from the one printed.
Swapping the arguments in the function call.
5fill in blank
hard

Fill all three blanks to call the function power with base 3 and exponent 4, store the result in res, and print it.

C
#include <stdio.h>

int power(int base, int exp) {
    int result = 1;
    for (int i = 0; i < exp; i++) {
        result *= base;
    }
    return result;
}

int main() {
    int [1] = [2];
    printf("%d\n", [3]);
    return 0;
}
Drag options to blanks, or click blank then click option'
Ares
Bpower(3, 4)
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in declaration and print.
Calling the function with wrong arguments.

Practice

(1/5)
1. What does it mean to call a function in C?
easy
A. Execute the code inside the function by using its name and parentheses
B. Define the function with its code block
C. Declare the function prototype
D. Write comments about the function

Solution

  1. Step 1: Understand function calling

    Calling a function means running the code inside it by using its name followed by parentheses.
  2. Step 2: Differentiate from defining or declaring

    Defining or declaring a function is writing it, not running it. Calling is executing it.
  3. Final Answer:

    Execute the code inside the function by using its name and parentheses -> Option A
  4. Quick Check:

    Function call = run code by name() [OK]
Hint: Calling means running code by writing functionName() [OK]
Common Mistakes:
  • Confusing calling with defining the function
  • Thinking calling means declaring the function prototype
  • Believing calling is writing comments
2. Which of the following is the correct syntax to call a function named printMessage in C?
easy
A. printMessage();
B. call printMessage;
C. printMessage;
D. function printMessage();

Solution

  1. Step 1: Recall function call syntax

    In C, calling a function requires its name followed by parentheses and a semicolon.
  2. Step 2: Check each option

    printMessage(); uses correct syntax: function name + parentheses + semicolon. Others are invalid syntax.
  3. Final Answer:

    printMessage(); -> Option A
  4. Quick Check:

    Function call syntax = name() [OK]
Hint: Function call always ends with (); [OK]
Common Mistakes:
  • Omitting parentheses when calling
  • Using keywords like 'call' which don't exist in C
  • Missing semicolon at the end
3. What will be the output of this C program?
void greet() {
    printf("Hello!\n");
}

int main() {
    greet();
    return 0;
}
medium
A. Compilation error
B. Hello!
C. No output
D. greet()

Solution

  1. Step 1: Understand function greet()

    The function greet() prints "Hello!" followed by a newline.
  2. Step 2: Check main() function call

    Main calls greet(), so the program prints "Hello!" on the screen.
  3. Final Answer:

    Hello! -> Option B
  4. Quick Check:

    Calling greet() prints Hello! [OK]
Hint: Calling greet() prints its message exactly [OK]
Common Mistakes:
  • Thinking function name prints output
  • Assuming no output without explicit main print
  • Confusing function call with declaration
4. Identify the error in this code snippet:
void sayHi() {
    printf("Hi!\n");
}

int main() {
    sayHi;
    return 0;
}
medium
A. printf statement is incorrect
B. Missing semicolon after sayHi
C. Function sayHi is not declared
D. Missing parentheses when calling sayHi

Solution

  1. Step 1: Check function call syntax

    In main(), sayHi is written without parentheses, so it is not a function call.
  2. Step 2: Correct function call

    To call sayHi, it must be written as sayHi(); with parentheses.
  3. Final Answer:

    Missing parentheses when calling sayHi -> Option D
  4. Quick Check:

    Function call needs () [OK]
Hint: Always use () to call a function [OK]
Common Mistakes:
  • Omitting parentheses when calling functions
  • Confusing function name with variable
  • Assuming semicolon alone calls function
5. Given the function below, how would you call multiply to multiply 4 and 5 and print the result?
int multiply(int a, int b) {
    return a * b;
}

int main() {
    // Your code here
    return 0;
}
hard
A. int result = multiply(4, 5);
B. multiply(4, 5);
C. printf("%d", multiply(4, 5));
D. print(multiply(4, 5));

Solution

  1. Step 1: Understand multiply function

    It returns the product of two integers.
  2. Step 2: Call multiply and print result

    To show output, call multiply(4, 5) inside printf with %d format.
  3. Final Answer:

    printf("%d", multiply(4, 5)); -> Option C
  4. Quick Check:

    Use printf to display function return [OK]
Hint: Use printf to show returned value from function [OK]
Common Mistakes:
  • Calling multiply without printing result
  • Using print() instead of printf() in C
  • Assigning result but not printing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard