1.

Functions

Answer»
int sum (int a, int b){ // Declaration
return a+b;
}
int main(){
int first_number= 10;
int second_number = 20;
cout<< sum(first_number, second_number); // Calling a function
}

When a function is called, it is a collection of statements that are all executed at the same time. Every function has a name that is used to refer to it when it is called. A function typically contains the following parts:



  • Return value: Return value is the value that the function return at the end of the function. A function must return the value of the same data type as mentioned in the function declaration.


  • Parameters: The parameters are the placeholders of the values passed on to them. In the above code, a and b are the function parameters.


  • Declaration: It contains the name of the function, its return type, and parameter list. 




Discussion

No Comment Found