0
0
C++programming~10 mins

Function parameters 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 declare a function that takes an integer parameter named x.

C++
void printNumber([1]) {
    std::cout << x << std::endl;
}
Drag options to blanks, or click blank then click option'
Aint
Bx int
Cint x
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Writing the parameter name before the type.
Omitting the parameter name.
Using a variable name without a type.
2fill in blank
medium

Complete the function call to pass the integer 5 to the function printNumber.

C++
printNumber([1]);
Drag options to blanks, or click blank then click option'
Aint
Bx
C"5"
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of an integer.
Passing the parameter name instead of a value.
3fill in blank
hard

Fix the error in the function definition by completing the parameter list correctly.

C++
void add([1]) {
    std::cout << a + b << std::endl;
}
Drag options to blanks, or click blank then click option'
Aa int, b int
Bint a, int b
Cint a b
Dint a; int b
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons instead of commas.
Writing parameter names before types.
Omitting commas between parameters.
4fill in blank
hard

Fill both blanks to declare a function that takes a float and a char parameter.

C++
void process([1], [2]) {
    // function body
}
Drag options to blanks, or click blank then click option'
Afloat value
Bint number
Cchar letter
Ddouble data
Attempts:
3 left
💡 Hint
Common Mistakes
Using int instead of float.
Using double instead of float.
Mixing up parameter types.
5fill in blank
hard

Fill all three blanks to create a function that returns the sum of two integers and one float.

C++
auto sum([1], [2], [3]) {
    return a + b + c;
}
Drag options to blanks, or click blank then click option'
Aint a
Bint b
Cfloat c
Ddouble d
Attempts:
3 left
💡 Hint
Common Mistakes
Using double instead of float.
Using wrong parameter names.
Missing parameter types.