Multiple Return

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Azaz ul haq
    New Member
    • Dec 2007
    • 4

    Multiple Return

    How we can return multiple values from a function?
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by Azaz ul haq
    How we can return multiple values from a function?

    You can do this by passing the parameters which will be modified by the function with the values.
    This logic is there in C# where you specify the parameter is typw IN or type OUT

    Raghuram

    Comment

    • olakara
      New Member
      • Nov 2006
      • 18

      #3
      Originally posted by Azaz ul haq
      How we can return multiple values from a function?
      Hi,
      You can make use of reference variables in C++ to achieve this.

      Regards,
      Abdel

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        With pointers.

        You make a function argument to be the pointer to the type and once the function is called actually the passed parameter will have the value modified from inside the function.(in c,in c++ you can use references)

        e.g

        [CODE=c]void Increase(int *pInt)
        {
        (*pInt)++;
        }

        //test call
        int k=5;
        Increase(&k);//k becomes 6;[/CODE]

        More pointers you put as function arguments,more values you can return from the function+1 if you have a return type other then a void.

        Savage

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Savage! Good to see you back!

          Azaz ul haq - please check your Private Messages, accessible via the PMs link in the top right corner of the page.

          Comment

          • Savage
            Recognized Expert Top Contributor
            • Feb 2007
            • 1759

            #6
            Originally posted by sicarie
            Savage! Good to see you back!

            Azaz ul haq - please check your Private Messages, accessible via the PMs link in the top right corner of the page.
            Thanks sicarie,it has been a while..

            Savage

            Comment

            Working...