Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
2.3k views
in Functions by (49.1k points)
closed by

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

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

The return statement:

Returning from the function is done by using the return statement. The return statement stops execution and returns to the calling function. When a return statement is executed, the function is terminated immediately at that point. The return statement is used to return from a function. It is categorized as a jump statement because it terminates the execution of the function and transfer the control to the called statement.

Syntax:

return expression/variable;

Example :

retum(a + b); retum(a);

return; // to terminate the function

The Returning values:

The functions that return no value is declared as void. The data type of a function is treated as int, if no data type is explicitly mentioned.

For example:

int add (int, int);

add (int, int);

In both prototypes, the return value is int, because by default the return value of a function in C++ is of type int.

Returning Non – integer values: A string can also be returned to a calling statement.

 

Output:

Example: Function with Non Integer Return Chennai

The Returning by reference:

#include

using namespace std;

int main( )

{

int n 1 = 150;

int &n 1 ref = n1;

cout << “\nThe Value of N1 = “<< n1 << “and n 1 Reference = ”<< n 1 ref; n 1 ref++;

cout << “\n After nl increased the Value of N1 = ”<< n1;

cout << “and n 1 Reference = ”<< n 1 ref;

retum(0);

}

Output: 

The Value of N1 = 150 and nl Reference =150 After n1 increased the Value of N1 = 151 and n1 Reference =151

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jan 11, 2021 in Functions by Padma01 (49.1k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...