Solved

# multi dimensional arrays

Posted on 1999-07-22
Medium Priority
156 Views
int n[5];

void func( int * pn )
{ .... }

func( n );

this is clear.
What to write in the 'func()' call in that case:

int n[5][5];

void func( int ** ppn )
{ .... }

func( ???? );

0
Question by:dib
• 2

Author Comment

ID: 1263787
Edited text of question.
0

LVL 10

Accepted Solution

rbr earned 200 total points
ID: 1263788
void func (int arr[][5])

0

LVL 10

Expert Comment

ID: 1263789
You have to know at the number of cols of your matrix. Another better way if the dimensions differs and you want to use the same function sveral times is to use the following structure

struct my_arr {
size_t rows;
size_t cols;
int **pparr;
}

struct my_arr *init_array (size_t cols,size_t rows)
{
struct my_arr *parr;
int i;

parr = calloc (1,sizeof (struct my_arr));
parr->cols=cols;
parr->rows=rows;

parr->pparr = calloc (cols,sizeof (int *));

for (i=0;i<rows;i++)       {
parr->pparr[i] = calloc (rows, sizeof (int));
}
return (parr);
}
void clear_array (struct my_arr *parr)
{
int i;
for (i=0;i<parr->rows;i++)       {
free(parr->pparr[i])
}
free (parr->pparr);
free (parr);
}

0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
###### Suggested Courses
Course of the Month11 days, 13 hours left to enroll