Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help--Arrays and Pointers

cekiceki Member Posts: 2
Hello there !
I am begginer in C programming.
Can someone explain me why the following is the same.
matrix[i][j] is the same as *(*(matrix+i)+j)
The following code works:
---------------------------------
int matrix[10][10],number=0;
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
*(*(matrix+i)+j)=number++;
---------------------------------
But when I define function like this:

void printMatrix(int **matrix,int rCount,int cCount)
{
int matrix[10][10],number=0;
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
*(*(matrix+i)+j)=number++;

}

and i try to call the function with real matrix
like this:
int matrix[10][10];
// here i create matrix
printfMatrix(matrix,10,10);
I get error message like this:
cannot convert int[][10] to int**;

Any help would bee nice!!!!!!!!



Comments

  • stoberstober Member Posts: 9,765 ✭✭✭
    change the function like this
    [code]
    void printMatrix(int matrix[][10],int rCount,int cCount)
    {
    // blabla
    }
    [/code]


    : Hello there !
    : I am begginer in C programming.
    : Can someone explain me why the following is the same.
    : matrix[i][j] is the same as *(*(matrix+i)+j)
    : The following code works:
    : ---------------------------------
    : int matrix[10][10],number=0;
    : for(int i=0;i<10;i++)
    : for(int j=0;j<10;j++)
    : *(*(matrix+i)+j)=number++;
    : ---------------------------------
    : But when I define function like this:
    :
    : void printMatrix(int **matrix,int rCount,int cCount)
    : {
    : int matrix[10][10],number=0;
    : for(int i=0;i<10;i++)
    : for(int j=0;j<10;j++)
    : *(*(matrix+i)+j)=number++;
    :
    : }
    :
    : and i try to call the function with real matrix
    : like this:
    : int matrix[10][10];
    : // here i create matrix
    : printfMatrix(matrix,10,10);
    : I get error message like this:
    : cannot convert int[][10] to int**;
    :
    : Any help would bee nice!!!!!!!!
    :
    :
    :
    :

Sign In or Register to comment.