0

Hi could someone tell me how to pass a dynamic matrix to a function? Or where I have gone wrong? Thanks for the help!

for example:

void main()
{
int R,C;           /* r=rows, c=columns/*
double *A;     /* A is the matrix/*

/* I dynamically allocate my matrix (not too sure if correct)*/
double *A = malloc(R * C * sizeof(double)); 


/* assuming i have a function that calculates the determinant */
determinant(A,R,C);

/* and free it later*/
free(A);
}


void determinant(double *matrix, int r, int c)

have I passed the dynamic matrix to the function determinant correctly?

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by jephthah
0

quick note:

you've already declared 'A' as type double * ... so don't declare the type a second time when you allocate the memory

otherwise you're passing the pointer as declared correctly, but you may want to reconsider how you define the array to begin with.

This question has already been answered. 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.