Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   2-d Array (http://www.go4expert.com/forums/2-d-array-t14403/)

 kanaks_go4ex 6Oct2008 23:42

2-d Array

How to pass the two dimensional arrays to functions ?
What are the ways to implement this type .

 oogabooga 11Oct2008 21:44

Re: 2-d Array

To pass a 2d (or higher) array you suppress the first dimension's size,
which means you have to pass it in as another variable.
Here is an example:
Code:

```#include <stdio.h> #define DIM_X  5 #define DIM_Y 10 void init_a( int a[][DIM_Y], int size) {     int x, y;     for (x = 0; x < size; ++x)         for (y = 0; y < DIM_Y; ++y)             a[x][y] = x * y; } void print_a( int a[][DIM_Y], int size) {     int x, y;     for (x = 0; x < size; ++x) {         for (y = 0; y < DIM_Y; ++y)             printf( "%4d ", a[x][y]);         printf( "\n");     } } int main() {   int a[ DIM_X][ DIM_Y];   init_a( a, DIM_X);   print_a( a, DIM_X);   return 0; }```

 All times are GMT +5.5. The time now is 05:49.