C++ Functions

C++ Functions A capacity is a gathering of explanations that together play out a various errand. Each C++ program has somewhere around one capacity, fundamental(), and every one of the least difficult projects can characterize different capacities. You can isolate your code into discrete capacities. How you split your code between the various capacities is dependent upon you, however sensibly, division is generally each capacity playing out a particular undertaking. A capacity statement tells the compiler the name, return type and boundaries of the capacity. The capacity characterized the real body of the capacity. The C++ standard library gives many implicit capacities that projects can call. For instance, the capacity strcat() links two strings, the capacity memcpy() duplicates one memory area to another and a lot more capacities. Capacities are known with different names, like techniques or subroutines or strategies, and so forth

Defining a Function

The general term of a C++ function

Characterizing a Function The overall type of a C++ work


return_typefunction_name(boundarylist ) {body of the capacity
}


A C++ work definition contains a limit header and a limit body. Following are to a great extent the bits of the limit




A C++ work definition comprises of a capacity header and a capacity body. Following are altogether the pieces of the capacity

Return Type

The capacity can return a worth. return_type is the information sort of the worth returned by the capacity. A few capacities perform wanted tasks without returning a worth. For this situation return_type is the catchphrase void.

Function name

This is the genuine name of the Function Name.

Parameters

Boundaries are like placeholders. While calling the capacity, pass the worth to the boundary. This worth is known as the real boundary or boundary. The boundary list alludes to the sort, request, and number of capacity boundaries. Boundaries are discretionary; that is, the capacity may not contain any boundaries.

.Function Body

The capacity body contains a bunch of proclamations that characterize t he capacity of the capacity.

Example1

The following is the source code of the capacity named head(). This capacity takes two contentions num1 and num2 and returns the biggest of the two contentions


// function returning the head between two numbers//

int head(int num1, int num2) {

// local variable declaration//

   int result;

 if (num1 > num2)

      result = num1;

   else

      result = num2;

   return result;

}

example 2

output