sorry about this question but I'm very curious (return)

This is a discussion on sorry about this question but I'm very curious (return) within the C++ Programming forums, part of the General Programming Boards category; well yeah it's actually about return see I see return in int main (actually it is "return 0;") and I ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    75

    sorry about this question but I'm very curious (return)

    well yeah


    it's actually about return

    see I see return in int main (actually it is "return 0;")
    and I was wondering what is it for I mean like why is there a return at the end of int main whats it for and what does it return and why does it return it can some one plz let me know



    cheers


    stealth

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    most operating system has a term called "return value", meaning that when a process is terminated, it returns a value, also called an error code. this is the normal way for the process to let the OS know its termination status. By convension, 0 means normal termination with no problems. Other non-zero values might indicated some problems in the process execution or terminsation.
    The compiler takes the value returned by the main() function and returns it to the operating system which started the program as an "Error code", thisis why you see at the end of a norma main() program the "return 0;" line.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    75

    hmmmm

    well man I dont really understand looks to me that it's something like this:


    everytime a program closes or evertime a process or whatever ends it has to return wether it ended properly or with an error or something well then, so 0 returns a normal termination I still dont know why, what happens if it doesnt terminate properly does the program cause the whole computer to lock up is that why my computer locks up,also I saw this code when I was learning about classes it went something like this:


    int GetAge()
    {
    return ItsAge;
    }


    well something liek that anyway whats actually happenning here odes that mean that earlier on when the class was made that that certain int ('int GetAge()') has a set return value so like if it returns "ItsAge" then that is a normal termination, if so does that mean I can control which things are coinsidered errors in my programs and which things arent


    thanks for the help man



    cheers



    stealth

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    > does the program cause the whole computer to lock up
    No, that's a bug.

    An error exit condition is a normal exit from main, with some non-zero value indicating that there was a problem.

    Say you had a small program which implements the DOS "copy" program to copy a file.

    Normal exit would be the file is copied normally, and main returns 0.

    But what about if the disk is full? The program detects this, and doesn't copy the file (nor does it fall over and take the rest of the machine with it). But how to tell the outside world that this is what happened. In your description of your program, you would say that an exit status of 1 (return 1; in main) would mean disk full. Other numbers could be used for other reasons.

    In the wider scheme, say your program was being used as a component of some larger system (typically a shell script or batch file). The script would look at the status (or errorlevel as it's called in DOS), and generate the appropriate response back to the user (or to it's own caller).

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    75

    oh

    hmmmmm


    ok


    thanks for the help man


    cheers


    stealth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  4. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  5. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21