Terminating NULL
2 posters
:: C Languages :: C++ :: Help!
Page 1 of 1
Re: Terminating NULL
I don't quite understand what you mean. Do you want your program to just terminate or end at some specific line? If so then there are a few ways to do so
Here are the ways that I commonly use:
1)Call for a system command, system(); and within the parenthesis pass in a string parameter,"PAUSE." So that you get:
system("PAUSE");
This command should be put at the end of your main(). Now there are many problems with using the system(), so I don't recommend using it for large programs. For largrer programs you should include a separate library called conio.h and use the function getch(); before "return 0;" at the end of your main() which is much better for a variety of reasons.
#include <conio.h>
int main()
{
//Some code
getch();
return 0;
}
Here are the ways that I commonly use:
1)Call for a system command, system(); and within the parenthesis pass in a string parameter,"PAUSE." So that you get:
system("PAUSE");
This command should be put at the end of your main(). Now there are many problems with using the system(), so I don't recommend using it for large programs. For largrer programs you should include a separate library called conio.h and use the function getch(); before "return 0;" at the end of your main() which is much better for a variety of reasons.
#include <conio.h>
int main()
{
//Some code
getch();
return 0;
}
legolizard- Posts : 137
Join date : 2011-08-01
Location : On planet Char.
Re: Terminating NULL
No. I mean is there a way to return a NULL? I want to return a NULL, but I don't know how in C++.legolizard wrote:I don't quite understand what you mean. Do you want your program to just terminate or end at some specific line? If so then there are a few ways to do so
Here are the ways that I commonly use:
1)Call for a system command, system(); and within the parenthesis pass in a string parameter,"PAUSE." So that you get:
system("PAUSE");
This command should be put at the end of your main(). Now there are many problems with using the system(), so I don't recommend using it for large programs. For largrer programs you should include a separate library called conio.h and use the function getch(); before "return 0;" at the end of your main() which is much better for a variety of reasons.
#include
int main()
{
//Some code
getch();
return 0;
}
Re: Terminating NULL
Well sort of. You see there are two basic groups of functions in C++, functions that do not return anything such as as void functions and constructors and then you have functions that must return something, preferably one that matches the type of function. For example, the main() must always return 0 because the main() is of integer type and well zero is an integer, this is why we have the keyword return at the bottom. Now NULL by definition means nothing so technically void functions return null, however you never ever go :return NULL, because they do so automatically.
legolizard- Posts : 137
Join date : 2011-08-01
Location : On planet Char.
Re: Terminating NULL
Okay! Thanks for the help!.legolizard wrote:Well sort of. You see there are two basic groups of functions in C++, functions that do not return anything such as as void functions and constructors and then you have functions that must return something, preferably one that matches the type of function. For example, the main() must always return 0 because the main() is of integer type and well zero is an integer, this is why we have the keyword return at the bottom. Now NULL by definition means nothing so technically void functions return null, however you never ever go :return NULL, because they do so automatically.
:: C Languages :: C++ :: Help!
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|