Hello,

How to call a function which takes dynamic array argument? That is to say, if I have:

void fctn (int *a[], int n)
{
*a = &n;
//do stuff with a.
}

How to call this in main? Must I have another array declared in main to call it with?

Thanks for the help.

Just make sure you match the expected type. In this case, int *a[] is equivalent to int **a , so I would expect the function to be called something like this:

int main()
{
  int **a;

  // ...

  fctn ( a, SIZE );
}
int main()
{
    int* a = new int[2];
    func(a);
    delete[] a;
}

void func( int* a )
{
    // Do something with a
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.