return和exit

Posted lnlin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了return和exit相关的知识,希望对你有一定的参考价值。

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

示例:

[[email protected] testForC]$ ./exit.test 
q
[[email protected] testForC]$ ./exit.test 
a
Here!
[[email protected] 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!
");

    return 0;
}

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

    return;
}

 

以上是关于return和exit的主要内容,如果未能解决你的问题,请参考以下文章