Return Statement in C| when I used print just after if condition it gave me "Equal multiple times" but when i used return statement it game me single time?
-
void main() {char name[50],came[50];int i; gets(name); gets(came); for(i=0;name[i]||came[i];i++) {int d=name[i]-came[i]; if(d==0) return printf("Equal"); else return printf("Unequal"); } }
-
void main() {char name[50],came[50];int i; gets(name); gets(came); for(i=0;name[i]||came[i];i++) {int d=name[i]-came[i]; if(d==0) return printf("Equal"); else return printf("Unequal"); } }
Using return where you do, exits the current function you are in, in this case it is main(). So you are exiting the program when you call return.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
-
void main() {char name[50],came[50];int i; gets(name); gets(came); for(i=0;name[i]||came[i];i++) {int d=name[i]-came[i]; if(d==0) return printf("Equal"); else return printf("Unequal"); } }