Discussion :: Functions - Yes / No Questions (Q.No.3)
|Andras Joo said: (Oct 1, 2010)|
|Consider the following exception:
if (condition) goto lab1;
lab1: return 1;
lab2: return 0;
|Niziak said: (Jan 1, 2011)|
|Warning is not error, so I didn't see problems with two returns :)|
|Vijay said: (Jan 23, 2011)|
int mul(int, int); /* Function prototype declaration */
int a = 4, b = 3, c;
c = add(a, b);
printf("c = %d\n", c);
int mul(int a, int b) /* Function definition*/
return (a * b);
return (a - b);
I think in this case they can come one after the other.
|Ajeet Kumar said: (Jun 2, 2011)|
printf("Enter the two value which u want");
printf("The final value is:=%d",c);
int mera(int a,int b)
|Manche Shekhar said: (Mar 26, 2012)|
|For this program the output is:
In function `main':
undefined reference to `add'
Because here we declare mul( ) function but we are passing values to add.
|John said: (Jun 8, 2012)|
|I get no warnings at all when compiling a program containing this:
int USART_Transmit( char data )
while ( !( UCSRA & (1<<UDRE)) );/* Wait for empty transmit buffer */
UDR = data;/* Put data into buffer, sends the data */
|Jagadeesh said: (Jun 10, 2012)|
|When ever in a function return statement is executed imedietly, the function that was called will take control over the program so it is not matter of no of return statements but the first one only gets executed.
I aslo tested in GNU compiler and also in Dev C++ both are not generating any warning.
|Abhishek said: (Jul 2, 2013)|
|In a recursive function, there may have more than one return statement. But then its not generating any warning. Then how ans can be yes? consider this example:
int large(int x,int y)
/*it will return y value successfully. It will not give any warning.*/
|Pushpa said: (Feb 11, 2014)|
|Warning is not come in gcc compilation.|
|Suresh said: (Oct 6, 2014)|
2 int print()
4 int b = 7,a = 2;
5 printf("This is my machine\n");
6 return (a+b);
7 return (a-b);
10 int main()
13 int x = print();
15 printf("returned value is : %d\n ",x);
16 return 0;
This program, in GCC does not give any warnings.
|Luki said: (Nov 18, 2015)|
|Visual Studio also doesn't generate warning for this code:
int mul(int a, int b)
return (a * b);
return (a - b); /* Warning: Unreachable code */
|Shubham Tripathi said: (Oct 6, 2016)|
|Some compilers don't make warnings. The code is simply unreachable. What is the reason?|
|Kalidas Tate said: (Dec 30, 2016)|
I have compiled same code which has two successive return statements with GCC version 4.8.3 20140627.
I didn't get any warning.
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.