C++ return和exit的區別

return 結束當前函數

exit 結束整個進程,包含頭文件:#include  <stdlib.h>

直接上代碼:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string>

using namespace std;

void fun()
{
	printf("in fun\n");
	return ;
	//exit(0);
}

int main()
{
	fun();

	printf("after fun\n");

	system("pause");
	return 0;
}

fun()函數中使用return:                                                             fun()函數中使用exit:

     

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章