0
0
C++programming~10 mins

Function declaration and definition 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 named add that returns an int.

C++
int [1](int a, int b);
Drag options to blanks, or click blank then click option'
Acalculate
Bsum
Cadd
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than 'add'.
Omitting the function name.
2fill in blank
medium

Complete the code to define the function add that returns the sum of two integers.

C++
int add(int a, int b) {
    return a [1] b;
}
Drag options to blanks, or click blank then click option'
A/
B+
C*
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting the return statement.
3fill in blank
hard

Fix the error in the function definition to correctly declare the return type.

C++
[1] add(int a, int b) {
    return a + b;
}
Drag options to blanks, or click blank then click option'
Adouble
Bvoid
Cfloat
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as return type when the function returns a value.
Using floating-point types when integers are returned.
4fill in blank
hard

Fill both blanks to declare and define a function named multiply that returns the product of two int parameters.

C++
int [1](int x, int y) {
    return x [2] y;
}
Drag options to blanks, or click blank then click option'
Amultiply
Badd
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition operator instead of multiplication.
Using wrong function name.
5fill in blank
hard

Fill all three blanks to declare and define a function named maxValue that returns the greater of two int values.

C++
int [1](int a, int b) {
    if (a [2] b) {
        return a;
    } else {
        return [3];
    }
}
Drag options to blanks, or click blank then click option'
AmaxValue
B>
Cb
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than operator instead of greater than.
Returning the wrong variable in the else block.