The difference between return and break is resolved
- 2020-04-02 02:13:10
- OfStack
#include <stdio.h>
void a(void)
{
int i;
for(i=0;i<5;++i)
{
printf("AAAAn");
//break; //break To terminate for Cycle, when i=0<5 Set up to perform AAAA And then break End of the cycle
//So the output is AAAA once BBBB once. Comment out the break and replace it with return
return;
}
printf("BBBBn");
}
int main(void)
{
a();
return 0;
}
/*
----------------------
The code by C-Free 5.0 Write and output debugging results
-------------- The output ---------------
break The results:
AAAA
BBBB
return The results:
AAAA
------ conclusion -----
return and break The difference between, break Is to terminate the loop, and return Is empty in the expression (void) When, not to be adjusted
The function returns any value, terminating the function. Another meaning is to represent the return from the called function to the continuation of the main function
Line, can be returned with a return value, by return The following parameter is specified. Such as:
int i()
return 10;
*/