Tamil Nadu Board of Secondary EducationHSC Science Class 11th

What are the different forms of function return? Explain with example. - Computer Science

Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Answer in Brief

What are the different forms of function return? Explain with example.

Advertisement Remove all ads

Solution

Different forms of User-defined Function declarations:

Function without return value and without parameter
The following program is an example of a function with no return and no arguments passed.
The name of the function is display( ), its return data type is void and it does not have any argument.

#include <iostream>
using namespace std;
void display( )
{
cout<<“Function without parameter and return value”;
}
int main()
{
display( ); // Function calling statement//
return(O);
}

Output :

Function without parameter and return value
A Function with return value and without parameter
The name of the function is display(), its return type is int and it does not have any argument. The return statement returns a value to the calling function and transfers the program control back to the calling statement.

#include <iostream>
using namespace std;
int display( )
{
int a, b, s;
cout<<“Enter 2 numbers:
cin>>a>>b;
s=a+b;
return s;
}
int main( )
{
int m=display( );
cout<<“\nThe Sum=”<<m;
return(0);
}
OUTPUT :
Enter 2 numbers: 10 30
The Sum = 40

Concept: Returning from Function
  Is there an error in this question or solution?

APPEARS IN

Tamil Nadu Board Samacheer Kalvi Class 11th Computer Science Answers Guide
Chapter 11 Functions
Evaluation - Section - D | Q 3. | Page 205
Share
Notifications

View all notifications


      Forgot password?
View in app×