+ 1

Why in c nested-if ,there is no use of "return" statement in end of code but the code run. some one explain it.

27th Mar 2020, 4:45 PM
Abdul Wahab Junaid
Abdul Wahab Junaid - avatar
5 odpowiedzi
+ 2
If it's a void function then `return` is not necessary. Why not show the code so everything will be clearer?
27th Mar 2020, 4:53 PM
Ipang
+ 2
I'm not sure how it is in C. But in C++ if we don't explicitly write any `return` statement, then the compiler will add one, assuming to return 0. This is in regards to main function specifically, not any regular function. I am more concerned with the nested `if`. The inner `if` block is not surrounded by curly brackets. Although the code works, I personally would prefer to wrap the inner `if` block for the sake of readability. Besides, the inner block contains multiple instructions : )
27th Mar 2020, 5:25 PM
Ipang
+ 2
Thanks for conversation. Ipang
27th Mar 2020, 5:42 PM
Abdul Wahab Junaid
Abdul Wahab Junaid - avatar
+ 1
#include <stdio.h> int main() { int profit = 1400; int clients = 18; int bonus; if (profit > 1000) if (clients > 15) bonus = 100; else bonus = 25; printf("%d", bonus); } but in this we use "int main" but in end, no required any return statement and answer is true.
27th Mar 2020, 5:18 PM
Abdul Wahab Junaid
Abdul Wahab Junaid - avatar
+ 1
Not a problem at all buddy 👌
27th Mar 2020, 5:45 PM
Ipang