Passing 2D array

I've written the following program. I am trying to pass the 2D array into function using pointer and change the value and reassign it into the array.

But it is giving error..how it works? How do I fix it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>

using namespace std;

void firstchange(int *a, int n)
{
    for(int i=0; i<n; i++)
        for(int j=i; j<n; j++)
        {
            *(a[i][j])=*(a[i][j]) *7;
        }
}

void secondchange(int *b, int n)
{
    for(int i=0; i<n; i++)
        for(int j=i; j<n; j++)
        {
            b[i][j]=b[i][j] +5;
        }
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);

    int n=3;

    int FirstArray[n][n] = {1,2,3,4,5,6,7,8,9};
    int SecondArray[n][n] = {1,2,3,4,5,6,7,8,9};

    firstchange(FirstArray,n);
    secondchange(SecondArray,n);

    for(int i=0; i<n; i++)
    {
        for(int j=i; j<n; j++)
        {
            cout<<FirstArray[i][j]<<" ";
        }
        cout<<endl;
    }

    for(int i=0; i<n; i++)
    {
        for(int j=i; j<n; j++)
        {
            cout<<SecondArray[i][j]<<" ";
        }
        cout<<endl;
    }

    return 0;
}
Last edited on
Are your program:
1) Not compiles
    * Is other code compiles correctly, i. e. is your compiler configured properly
    * If so, give us error message and corresponding code part.
2) Not running
    * Are you sure that it is not a problem with automatically closing console?
    * How do you run it?
    * Is there any error messages?
3) Gives an error when run
    * Is it system error message or error reported in console?
    * Give us error message and input which leads to error.
4) Not giving correct results
    * Tell what you entered, what you expected, and what you got.
    * Are you sure that results you expected are correct?
Last edited on
Topic archived. No new replies allowed.