Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to exit from a function but not from main()

Tags:

c++

c

function

Does C/C++ support terminating a program from a subroutine function i.e not main? So far I only found that exit and abort allow a user to terminate current function or process. If I'm not in main function, is there a way to terminate the whole program?

like image 587
Rajesh M Avatar asked Sep 05 '25 03:09

Rajesh M


2 Answers

If you are not in main() and in other function then also you can call exit() or abort() it will terminate your whole process.

where exit() will do required clean up where abort() will not perform that.

like image 173
Jeegar Patel Avatar answered Sep 08 '25 22:09

Jeegar Patel


exit(0) or exit(1)

If this is 0 or EXIT_SUCCESS, it indicates success. If it is EXIT_FAILURE, it indicates failure.

ref: See here

like image 21
nommyravian Avatar answered Sep 08 '25 23:09

nommyravian