return multiple values in c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepadaffine
    New Member
    • Dec 2006
    • 1

    return multiple values in c

    I am doing a program that calculate velocity and acceleration.
    I get all my input in main and then i call a sub function giving the input values as parameter and calculate velocity and acceleration.no w i want to return both these values to main can i do this when i do this i get only one correct value the other one is error value can you help
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    I would like to see the code you have that "does this".

    It you want to return n values from a function where n>1 then you will need to pass to that function at least n-1 pointers to locations where the outputs of the function will be store, the nth return value can either be passed back wia a pointer or returned as the return value of the function.

    For example

    Code:
    int SumAndProduct(int x, int y, int *product)
    {
       *product = x * y;
    
       return x + y;
    }

    Comment

    Working...