Thread: Return test

  1. #1
    Registered User
    Join Date
    Dec 2007

    Return test

    Whatever value i put in the if statement after return (0,1,-1) it comes back to
    So why is everybody putting all kind of values there?
    Is it a prank on noobs?
    Of course im not talking about values as a result of a calculation, that is different.

    #include <iostream>
    using namespace std;
    int If(void)
        int a=2,b=2;
        if (a==b) {cout << "If...\n"  ; return 1;}
        else      {cout << "Else...\n"; return 0;}
    int main()
        cout << "Main...\n";
        return 0;
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #2
    The larch
    Join Date
    May 2006
    A function is supposed to return the value to the calling function. It's only return from main that exits the program (since there is no calling function above that).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User GL.Sam's Avatar
    Join Date
    Aug 2009
    The main() return value indicates to calling envieronment whether program is terminated correctly, or something abnormal happened during the execution.
    The only good is knowledge and the only evil is ignorance.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. C++ Operator Overloading help
    By Bartosz in forum C++ Programming
    Replies: 2
    Last Post: 08-17-2005, 12:55 PM
  4. sort linked list using BST
    By Micko in forum C Programming
    Replies: 8
    Last Post: 10-04-2004, 02:04 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM