is there any command to end a program.
is there any command to end a program.
I believe there is a function, exit() ... you must include cstlib.h .... do a google search on that Good luck!
Yep, std::exit( int ) in <cstdlib> .
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Isn't it also in stdlib.h?
anyway, isn't it easier just to return 0?
As I understand it, C standard headers (including stdlib.h) are best used in C++ by dropping the ".h" and putting a "c" in front of it. This also puts the functions into the namespace "std". Although your way works, it's deprecated.Originally posted by Nuke
Isn't it also in stdlib.h?
You can, but only if you're in main. What if you call another function and decide (for some reason) to exit from there?anyway, isn't it easier just to return 0?
Last edited by roktsyntst; 06-01-2003 at 09:56 PM.
>Isn't it also in stdlib.h?
stdlib.h or cstdlib. However, take note that when you use cstdlib, everything will be in the std namespace.
>anyway, isn't it easier just to return 0?
From the control of main, yes. From elsewhere it's not so easy to return in one fell swoop without lots of annoying flags (exit is easier then). Also, for some compilers, exit is the only way to be sure that the return code you pass is not discarded. Many compilers will simply return 0 even if your code specifies a different return code.
My best code is written with the delete key.
Really? What compilers do this, and why (it's so easy not to do it).Many compilers will simply return 0 even if your code specifies a different return code.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
>What compilers do this
Pretty much any compiler that allows void main probably does so. The standard requires that main be invoked as if called like this:
However, some compilers (mostly older ones) do it more like this:Code:exit(main(argc, argv);
So if you have to have a useful exit code, it's more portable (in reality) to use the exit function instead of the return keyword.Code:main(argc, argv); exit(0);
My best code is written with the delete key.
I know for sure that VC++ does not do it, although it allows void main.
Don't know about exotic compilers though, don't really care for them.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
hey,
i just joined the team!
how abt "return;"??? - for void main()
return 0; - for int main()
wont that work too???
You shouldn't use void main( ) in the first place. It is nowhere in the standard for C++, and I'm pretty sure its not allowed in C either.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
void main() is the devil.
anyways, i dont see how using exit() is more portable than return 0 is. are you saying that if you tried to check the return value of a program, it will be 0, so it could cause some errors if you were doing something thats dependent on what a program returned? pretty complex concept or its just me .
The main time you want to use exit( ) is if you want to quit the program from a function other than main( ). In this case, a simple return statement won't do, so you have to use the exit( ) command.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie