Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# multi dimensional arrays

Posted on 1999-07-22
Medium Priority
153 Views
Last Modified: 2010-04-15
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
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 2
3 Comments

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.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ouâ€¦
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were smallâ€¦
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
###### Suggested Courses
Course of the Month5 days, left to enroll

#### 670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.