C++ Function with Parameters

Function with Parameters in C++:

A function with parameters in C++ is a function that takes input values when it is called. The parameters are specified within the parentheses following the function name. Here is the syntax of a function with parameters in C++:

return_type function_name(parameter_type parameter1, parameter_type parameter2, ...)
{
    // function body
}
  1. return_type: This is the data type of the value that the function will return after it is executed.

  2. function_name: This is the name of the function that is being defined.

  3. parameter_type: This is the data type of the input parameter.

  4. parameter1, parameter2, ...: These are the names of the input parameters that the function will accept.

  5. function body: This is the block of code that contains the statements to be executed when the function is called.

When the function is called, the actual values (arguments) are passed to the parameters. These arguments must match the data types and the order of the parameters in the function definition.

For example, consider the following function with parameters:

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

In this example: - int is the return type - add is the function name - int a and int b are the input parameters - return a + b is the function body, which returns the sum of a and b.

When this function is called, it takes two integers as arguments and returns their sum.