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?

Recommended Answers

All 2 Replies

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.

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.