Computer Science, asked by KIRANKIRRU6294, 1 year ago

Pick the correct statements.
I. The body of a function should have only one return statement.
II. The body of a function may have many return statements.
III. A function can return only one value to the calling environment.
IV. If return statement is omitted, then the function does its job but returns no value to the calling environment.
A.I and II
B.I and III
C.II and III
D.II and IV

Answers

Answered by Vaishnavi18
1
II. The body of a function may have many return statements.
III. A function can return only one value to the calling environment.

The above statements are correct.
So the answer is option C. II and III
Answered by ankhidassarma9
0

Answer:

C.II and III

Explanation:

  • The body of a function may have many return statements.
  • But function can return only one value to the calling environment.
  • A return statement ends the execution of a function, and returns control to the calling function.
  • Consider the following example:

     main()

      {

      int a=5,fact;

      fact=rec(a);

      printf("Factorial value of %d =",fact);

}

int rec(int x)

{

int f;

if(x==1)

return(1);

else

f=x*rec(x-1);

return (f);

}

  • In the above example function rec(x) has 2 return statements in its body but it will return only one value , either 1 or the value of 'f'.
  • if x is 1 , the function will execute return(1) and will return 1.
  • else, the function will execute return (f) and will return the value of 'f'.

 

Similar questions