multi dimensional arrays

Posted on 1999-07-22
Medium Priority
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( ???? );

Question by:dib
  • 2

Author Comment

ID: 1263787
Edited text of question.
LVL 10

Accepted Solution

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

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->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);
      free (parr);


Featured Post

WEBINAR: GDPR Implemented - Tips & Lessons Learned

Join the WatchGuard team on Thursday, March 29th as we recount some valuable lessons learned in weighing the needs of a business against the new regulatory environment, look ahead at the two months left before implementation, and help you understand the steps you can take today!

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.

Join & Write 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.

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

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

Join & Ask a Question