Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. return program

return program

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KARFER
    wrote on last edited by
    #1

    i want to know here that when i write a function like this int add (int a,int b) { int sum=0; sum=a+b; return sum; } i return sum but return sum to where.... that what i hope to know thank's for all

    To Be Or Not To Be (KARFER)

    M H 2 Replies Last reply
    0
    • K KARFER

      i want to know here that when i write a function like this int add (int a,int b) { int sum=0; sum=a+b; return sum; } i return sum but return sum to where.... that what i hope to know thank's for all

      To Be Or Not To Be (KARFER)

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      The value of sum is returned to the caller of add(). Somewhere else in your code you'd call add... int SumFromAdd = add(2,3); //SumFromAdd == 5 You can also choose to igore return values... add(2,3); // add() has been called but the return value wasn't used Note that there's no need to initialize sum to 0 in your function since the next line you initialize it to the sum of the two passed integers. You could shorten your function to: int add (int a,int b) { return a+b; } Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      1 Reply Last reply
      0
      • K KARFER

        i want to know here that when i write a function like this int add (int a,int b) { int sum=0; sum=a+b; return sum; } i return sum but return sum to where.... that what i hope to know thank's for all

        To Be Or Not To Be (KARFER)

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Sometimes you need to return value so you use of this cause here is two samples:

        int add (int a,int b)
        {
        int sum;
        sum=a+b;
        return sum;
        }

        void test()
        {
        int c;
        c=add(2,2);
        }
        ////////////////////////////////////

        Cstring add ()
        {
        CString str;
        SYSTEMTIME st;
        GetLocalTime(&st);
        str.Format("%d:%d:%d:",st.wHour,st.wMinute,st.wSecond);

        return str;
        }
        void test()
        {
        MessageBox(add());
        }


        WhiteSky


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups