Quiz on C++ Functions

Welcome to the C++ Functions Quiz! This quiz is designed to test your knowledge and deepen your understanding of functions in C++. Each question comes with a thorough explanation, helping you understand both the correct answers and the principles behind them. Covering topics from basic function definitions and calls to advanced concepts like recursion, inline functions, and function overloading, this quiz provides a comprehensive review of C++ functions.

Ready to challenge yourself? Let’s learn C++ functions !

Last Updated :
Discuss
Comments

Question 1

Which of the following is the correct syntax for a function declaration?

  • int function();

  • function int();

  • int function{};

  • int function[];

Question 2

What is the default return type if it is not specified in the function definition?

  • char

  • void

  • float

  • int

Question 3

What is the output of the below program?

C++
void display() { 
  cout << "Hello, World!"; 
}

int main()
{
    display();
    return 0;
}
  • Hello

  • World

  • Hello, World!

  • Error

Question 4

What does the return statement do in a function?

  • Ends the function

  • Passes control back to the caller

  • Returns a value to the caller

  • All of the above

Question 5

What keyword is used to declare a function that does not return a value?

  • int

  • float

  • void

  • return

Question 6

In the following function declaration, how many formal parameters are there?

C++
double calculate(double value1, double value2);
  • 1

  • 2

  • 0

  • 2 actual parameters

Question 7

Which of the following is used to define a function outside of a class declaration?

  • ::

  • .

  • ->

  • *

Question 8

Which among the following correctly explains a function prototype?


  • The actual body of the function

  • The first line of the function definition

  • A declaration of the function that specifies the function’s name, return type, and parameters

  • A dummy function

Question 9

What is the output of the below function with default arguments?

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

int main()
{
    cout << add(2);
    return 0;
}

function with default arguments?


  • 2

  • 5

  • 3

  • Error

Question 10

Which among the following best describes the function overloading?

  • Defining multiple functions with the same name but different parameters

  • Defining multiple functions with different names and parameters

  • Using the same function name for different return types

  • Defining multiple functions with the same name and parameters

There are 25 questions to complete.

Take a part in the ongoing discussion