What is the impact of warning: wreturn-type in our program?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the impact of warning: wreturn-type in our program??

Eg. Int function1 (int a){ If() function2 (); function3(); } Or int LCM(int num1,int num2){ static int i=1; if((num1%num2)==0) return num1; else if((num2%num1)==0) return num2; if(num1>num2) LCM(num1*++i,num2); LCM(num1,num2*++i); } int main(){ int num1,num2; printf("Input 1st number for LCM :"); scanf("%d",&num1); printf("\nInput 2nd number for LCM :"); scanf("%d",&num2); printf("\nThe LCM of %d and %d : %d",num1,num2,LCM(num1,num2)); }

15th Feb 2022, 5:14 AM
Raisun Lakra
3 Answers
+ 1
Such warning is shown when a non-void function *may* reach its block end without returning something. Meaning there's a chance where the function does not return something, while something somewhere was waiting for it. Try to ensure that your function returns something even when no conditional matched. You can return some default value or a value that indicates data invalidity. P.S. Please undo other languages in tags above. This is C/C++ specific, no other language uses wreturn-type as warning reference. https://www.cplusplus.com/forum/beginner/263126/
15th Feb 2022, 5:59 AM
Ipang
+ 1
Ipang what if I did not return anything. Will my program did not close or will something happen
15th Feb 2022, 8:04 AM
Raisun Lakra
+ 1
Unpredictable I guess, it depends on what the return value was used for. But at least you'll get that warning if the compiler is up to date.
15th Feb 2022, 9:24 AM
Ipang