Solution for Exercise 15-5
ex1505
#include <stdio.h> #include <stdlib.h> void sub(void); int main() { puts("This program quits before it's done."); sub(); puts("Or was that on purpose?"); return(0); } void sub(void) { puts("Which is the plan."); exit(0); }
Notes
* The exit() function is more of a termination command than the return keyword. exit() bails out of the code, halting the program wherever it's encountered.
* Even if your code uses exit() to terminate the program, I strongly recommend that you specify a return statement in the main() function. If anything, having return there, even if it's never reached, avoids a "control reaches end of non-void function" warning error.
Copyright © 1997-2024 by QPBC.
All rights reserved