# Thread: Function: passing 2-D array and returning a 1-D array from a function

1. ## Function: passing 2-D array and returning a 1-D array from a function

Code:
```main()
{
int a[10][5],j,i;
for(j=0;j<5;j++)
for(i=0;i<10;i++)
scanf("%d",&a[i][j]);

prior(a,j);
return 0;
}
int prior(int a[][],int j)
{
int m=-1,p,k,c[100];
for(p=0;p<j;p++)
for(k=0;k<3*n;k+3)
{
m=m+1;
c[m]=a[k][i]-(a[k+1][i]+a[k+2][i]);
}
return c[];```
Please correct my code to work....

2. The easiest thing to do is pass in the array where you want the results stored.
Eg.
Code:
```void prior( int a[][5], int c[], int j);
int main ( ) {
int a[10][5], c[100];
prior(a,c,j);
}```

3. ## Re:Function: passing 2-D array and returning a 1-D array from a function

Originally Posted by Salem
The easiest thing to do is pass in the array where you want the results stored.
Eg.
Code:
```void prior( int a[][5], int c[], int j);
int main ( ) {
int a[10][5], c[100];
prior(a,c,j);
}```
How can I return a 1-D array c[100]?

4. You just do things like
c[0] = 0;
inside your function, and that will make the change in the array declared in main.

5. Also, you haven't declared n or i and there is a missing '}' in your prior function ( the '}' is more likely a "copy and paste" problem)