I am getting compile error
C:\Dev-Cpp\Myproj\array.cpp cannot convert 'int (*)[3]' to 'int*' for argument '1' to 'int GetValues(int*)'

at the lines indicated in Red.

#include <cstdlib>
#include <iostream>

#define MAX 3
#define MIN 0 

using namespace std;
//int a[MAX][MAX];

int i,j;

int Display(int *a) {
    int n=2;
    for (i=MIN; i<MAX; i++) {
        for (j=MIN; j<MAX; j++) {
 //           cout << a[i][j] << "  "; 
            cout << *(a+ n*i+j) << "   ";
        }
    }
return EXIT_SUCCESS;
}
           
int GetValues (int *a)  {
    int n=2;
    for (i= MIN; i<MAX; i++) {
        for (j=MIN; j<MAX; j++) {
 //           cin >> a[i][j];
              cin >> *(a+ n*i+j);
        }
    }
    return EXIT_SUCCESS;
}
    
   
int main(int argc, char *argv[])
{
      int a[MAX][MAX];
      int dim = 2;
    cout << "enter values for a : " << endl ;
    GetValues(a);
    Display(a);
    cout<< endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Thanks and Regards
Ram Sharma

A two dimensional array isn't convertible to int*. Change Display and GetValues to take int a[MAX][MAX] as the parameter.

Hi,
But my intention was to use pointers.
By saying GetValues(a) or Display(a) I am sending the base address of the array as an argument and with in the functon would like to access the values by address and maipulate them.

Thanks and Regards
Ram Sharma

The array will still be passed as a pointer, no matter how you declare the function prototype / formal parameter.

int GetValues (int a[MAX][MAX])
int GetValues (int a[][MAX])
int GetValues (int (*a)[MAX])

are all equivalent to one another. The first is easy to remember because it is simply copy/paste of the array you want to pass into the function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.