0

In BCB, I need to pass a two dimensional array to a function Ratio. I did this without pointers or reference. Could any body else tell me what I should revise if I want to use pointers or reference for input?

double Ratio(double a[3], double VA[3][3], int i)
{
        double bg;
        if (a[i] <= 0.0) bg = VA[0][i];
        else if (a[i] > 	VA[2][i]) bg = VARAT[1][i];
        else bg = (1.-a[i]/VA[2][i])*(VA[0][i]-VA[1][i])+VA[2][i];
        return bg;
}

In the main:

int main()
{
...
        Ratio(a1, VA1, n);
...
}
3
Contributors
3
Replies
5
Views
10 Years
Discussion Span
Last Post by driplet
0

>>Could any body else tell me what I should revise if I want to use pointers or reference for input?

Nothing. Its already coded by reference because its not possible to pass an array any other way (pointers and references are essentially the same thing, although there are a couple minor differences).

If you really want to I suppose you code code it like this

double Ratio(double* a, double** VA, int i)
0

> double Ratio(double* a, double** VA, int i) Except that is no longer equivalent to double Ratio(double a[3], double VA[3][3], int i) The function will still compile with a ** pointer, but how you call the function changes.

To be the same as the OP's declaration, it would be double Ratio(double *a, double (*VA)[3], int i)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.