return从当前函数返回而exit结束正在运行的程序

示例:

[wangml@iZwz976helaylvgqok97prZ testForC]$ ./exit.test 
q
[wangml@iZwz976helaylvgqok97prZ testForC]$ ./exit.test
a
Here!
[wangml@iZwz976helaylvgqok97prZ testForC]$ cat exit.test.c
#include <stdio.h>
#include <stdlib.h>

void testExit(char ch);

int main(int argc, char **argv)
{
char ch;
scanf("%c", &ch);

testExit(ch);

printf("Here!\n");

return 0;
}

void testExit(char ch)
{
if (ch == 'q')
{
exit(1);
}

return;
}

 

转载请注明出处