+ 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.
5 odpowiedzi
+ 2
If it's a void function then `return` is not necessary. Why not show the code so everything will be clearer?
+ 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 : )
+ 2
Thanks for conversation. Ipang
+ 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.
+ 1
Not a problem at all buddy 👌