| 1. |
Explain the working of “function with arguments and with no return value”? With an example. |
|
Answer» Function with argument and no return value with an example: The calling function main() gives the function call to the called function by passing arguments or values. Then the called function takes the values and performs the calculations and it self gives the output but no value sent back to the calling function. # include<iostream> void sum (int x,int y) { int sum; sum = x + y; count<<"The sum is"<<sum; } int main() { void sum(int x,int y) int a,b; cout<<"enter the two number"; cin>>a>>b; sum(a,b); return 0; } In the above example, sum() is a user defined function. main() is a calling function which gives a function call sum (a, b); with actual arguments and The copy of values of a and b are sent to formal arguments x and y in the called function sum(). The function sum() performs addition and gives the result on the screen it can be deserved that. Here no value is sent back to the calling function main(). These kinds of functions are called “Function with arguments but no return values”. |
|