Jump to content

Return 0?

Go to solution Solved by Mr_KoKa,

After you run your app in your console by ./appname you can do

echo $?

which displays exit status of last executed command.

I'm new to programming and I am currently learning C++ in Ubuntu Linux.

I'm reading the book "Programming Principles and Practice using C++ Second Edition" and according to that, when using a Linux distribution the code "return 0" should actually return a zero.

My program does not display 0 anywhere.

Worth mentioning is that I used "return 0" at the end of a "main" function to end the program.

How do I make it return 0 to check if it works properly when I make more complicated programs?

Any help will be highly appreciated :)

Link to comment
https://linustechtips.com/topic/692282-return-0/
Share on other sites

Link to post
Share on other sites

I don't know anything about Linux, but as part of C++ you won't see the return value of any function to show up anywhere unless you ask for the console to print it.

i7-4790k | MSI Z97 GAMING-5 | Corsair Vengeance 16 GB | Samsung EVO-850 250GB SSD & WD blue 1 TB HDD | EVGA 1070 SC | Red NZXT H440 | Cooler Master G650W

 

Link to comment
https://linustechtips.com/topic/692282-return-0/#findComment-8878344
Share on other sites

Link to post
Share on other sites

7 minutes ago, Railgun said:

I don't know anything about Linux, but as part of C++ you won't see the return value of any function to show up anywhere unless you ask for the console to print it.

You mean output it just like I would a word?

Btw, here is the book extract:

Quote

First it’ll write Hello, World! to the screen, and then it will return a value 0 (zero) to whoever called it. Since main() is
called by “the system,” we won’t use that return value. However, on some systems (notably Unix/Linux) it can be used to check
whether the program succeeded. A zero (0) returned by main() indicates that the program terminated successfully.

 

Link to comment
https://linustechtips.com/topic/692282-return-0/#findComment-8878406
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×