Terminating NULL

 :: C Languages :: C++ :: Help!

View previous topic View next topic Go down

Terminating NULL

Post  David B on Mon Aug 01, 2011 2:16 pm

How do you add a terminating NULL to the end of a C++ program?
avatar
David B
Administrator
Administrator

Posts : 618
Join date : 2011-07-20
Location : The Twilight Zone!

View user profile http://programmingforums.forumotion.com/

Back to top Go down

Re: Terminating NULL

Post  legolizard on Mon Aug 01, 2011 2:25 pm

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;
}
avatar
legolizard

Posts : 137
Join date : 2011-08-01
Location : On planet Char.

View user profile

Back to top Go down

Re: Terminating NULL

Post  David B on Tue Aug 02, 2011 8:11 am

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;
}
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++.
avatar
David B
Administrator
Administrator

Posts : 618
Join date : 2011-07-20
Location : The Twilight Zone!

View user profile http://programmingforums.forumotion.com/

Back to top Go down

Re: Terminating NULL

Post  legolizard on Tue Aug 02, 2011 11:07 am

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.
avatar
legolizard

Posts : 137
Join date : 2011-08-01
Location : On planet Char.

View user profile

Back to top Go down

Re: Terminating NULL

Post  David B on Tue Aug 02, 2011 3:34 pm

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.
Okay! Thanks for the help!.
avatar
David B
Administrator
Administrator

Posts : 618
Join date : 2011-07-20
Location : The Twilight Zone!

View user profile http://programmingforums.forumotion.com/

Back to top Go down

Re: Terminating NULL

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 :: C Languages :: C++ :: Help!

 
Permissions in this forum:
You cannot reply to topics in this forum