Type of function return data in programming c

I need to use the exit (1) command in a function. Does this have anything to do with the return type of the function in which it is used?

+4
source share
1 answer

No. The exit function never returns, but instead terminates the process from which it called. The C compiler has no intuitive understanding and treats it like any other void return function.

This means that although exit will end your function, the C compiler will not see this. Therefore, it will still have the correct return, otherwise it will spit out warnings / errors (there will be a rather high level of errors). But that’s enough to get around

 int myFunc() { ... exit(exitCode); return 42; // Never hit but keeps C compiler happy } 
+4
source

All Articles