hamburger

The keyword used to transfer control from a function?

By BYJU'S Exam Prep

Updated on: September 25th, 2023

The keyword used to transfer control from a function back to the calling function is __________.

  1. If
  2. back
  3. go back
  4. return

Answer: D. return

The keyword used to transfer control from a function back to the calling function is return.

Solution

The if is used as a conditional statement to check whether the expression it’s true or false. The if isn’t having any relevance in transferring the control back to a function.
The back and return aren’t the keywords of the programing language.
The return statement ends a function’s execution and hands control back to the caller function. Immediately after the decision where execution returns to the caller function, a value will also be returned to the calling function in a return statement. Hence, the keyword used to transfer control from a function back to the calling function is return.

Example:

#include

int greater(int, int); /* Function prototype */

int main()

{

 int a = 5, b = 2, c;

 c = greater(a, b);

 printf(The greater elements is = %d\n, c);

 return 0;

}

int greater(int a, int b)

{

/* returns the value and control back to the main() function which is calling  */

if(a>b)

 return(a);

else

return(b);

}

In the given program, the main function is calling the greater function. After that, the greater function is returned and prints the output as 5.

☛ Related Questions:

Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium