1.

Explain function with argument and no return value with an example.

Answer»

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 itself gives the output but no value is sent back to the calling function. For example:

#include<iostream>

void sum(int x,int y)

{

int sum;

sum = x + y;

cout<<"the sum is"<<sum;

}

int main()

}

void sum(int x,int y)

int a,b;

cout<<"enter the two numbers";

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 a, b. 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. Here it can be observed that no value is sent back to the calling function main(). These kinds of functions are called “Function with argument but no return values”.



Discussion

No Comment Found

Related InterviewSolutions