0
0
C++programming~10 mins

Function calling in C++ - Interactive Code Practice

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

Complete the code to call the function greet.

C++
#include <iostream>

void greet() {
    std::cout << "Hello!" << std::endl;
}

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.
Trying to call the function with extra words like 'call'.
2fill in blank
medium

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

C++
#include <iostream>

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

int main() {
    int result = [1];
    std::cout << result << std::endl;
    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
Omitting parentheses or commas between arguments.
Using semicolons or spaces instead of commas.
3fill in blank
hard

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

C++
#include <iostream>

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

int main() {
    int product = [1];
    std::cout << product << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Amultiply(4 7)
Bmultiply(4, 7)
Cmultiply(4;7)
Dmultiply 4, 7
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces or semicolons instead of commas between arguments.
Omitting parentheses around arguments.
4fill in blank
hard

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

C++
#include <iostream>

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

int main() {
    double result = [1];
    std::cout << [2] << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
Adivide(10, 2)
Bresult
Cdivide(10 2)
D10 / 2
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to print the function call directly instead of the stored result.
Using spaces instead of commas between arguments.
5fill in blank
hard

Fill all three blanks to call concat with two strings and print the result.

C++
#include <iostream>
#include <string>

std::string concat(std::string s1, std::string s2) {
    return s1 + s2;
}

int main() {
    std::string combined = [1];
    std::cout << [2] << std::endl;
    return [3];
}
Drag options to blanks, or click blank then click option'
Aconcat("Hello, ", "World!")
Bcombined
C0
Dconcat("Hello" "World")
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting commas between string arguments.
Trying to print the function call directly instead of the variable.
Returning a non-zero value from main.