C Programming - Functions - Discussion

Discussion Forum : Functions - Yes / No Questions (Q.No. 8)
8.
In a function two return statements should never occur.
Yes
No
Answer: Option
Explanation:

No, In a function two return statements can occur but not successively.

Example:


#include <stdio.h>
int mul(int, int); /* Function prototype */

int main()
{
    int a = 0, b = 3, c;
    c = mul(a, b);
    printf("c = %d\n", c);
    return 0;
}

/* Two return statements in the mul() function */
int mul(int a, int b)
{
   if(a == 0 || b == 0)
   {
        return 0;
   }
   else
   {
        return (a * b);
   }
}

Output:
c = 0

Discussion:
2 comments Page 1 of 1.

Manoj said:   1 decade ago
In function mul() we are using two returns overall.

So format of question should be correct, like there should not be two consecutive return statements.

Afsha said:   5 years ago
Explain the answer.

Post your comments here:

Your comments will be displayed after verification.