C Programming - Functions - Discussion

Discussion Forum : Functions - Yes / No Questions (Q.No. 3)
3.
If a function contains two return statements successively, the compiler will generate warnings. Yes/No ?
Yes
No
Answer: Option
Explanation:

Yes. If a function contains two return statements successively, the compiler will generate "Unreachable code" warnings.

Example:


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

int main()
{
    int a = 4, b = 3, c;
    c = mul(a, b);
    printf("c = %d\n", c);
    return 0;
}
int mul(int a, int b)
{
   return (a * b);
   return (a - b); /* Warning: Unreachable code */
}

Output:
c = 12

Discussion:
13 comments Page 2 of 2.

Shubham Tripathi said:   9 years ago
Some compilers don't make warnings. The code is simply unreachable. What is the reason?

Niziak said:   1 decade ago
Warning is not error, so I didn't see problems with two returns :)

Pushpa said:   1 decade ago
Warning is not come in gcc compilation.


Post your comments here:

Your comments will be displayed after verification.