0
void Printarr(int col, int **arr){
    for(int i = 0; i < col; i++){
        for(int j = 0; j < col; j++)
            printf("%d ", arr[i][j]);
        printf("\n");
    }
}

this is function for printing array.

int main(){
    int col = 0;
    scanf("%d", &col);
    int abc[col][col];
    for(int i = 0; i < col; i++){
        for(int j = 0; j < col; j++){
            abc[i][j]=0;
        }
    }

and I want to print array abc.

Printarr(col, abc);

the error is when it run this code Printarr(col, abc);

No matching function for call to 'Printarr' 
Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
  • 2
    You can't. C++ does not work this way. This is not even valid C or C++, but relies on your compiler's custom extension to the C++ standard. If this was submitted as a homework assignment, most professors will fail it, for not being valid C++. – Sam Varshavchik Feb 22 '20 at 14:52
  • 2
    Does this answer your question? [How to pass 2D array (matrix) in a function in C?](https://stackoverflow.com/questions/3911400/how-to-pass-2d-array-matrix-in-a-function-in-c) – Ardent Coder Feb 22 '20 at 14:54
  • 2
    Note that a *bona fide* 2D array is an array of arrays, not an array of pointers, thus a corresponding function parameter must be a pointer to a (correct-length) array, not a pointer to a pointer. – John Bollinger Feb 22 '20 at 15:00
  • 1
    @walnut - The question was tagged C++ when Sam commented. Sam's comment is correct in C++ - which has never supported VLAs. VLAs are also optional in C11. – Peter Feb 22 '20 at 15:02
  • @walnut - Given that a number of C++ compilers support VLAs as a non-standard extension, it is understandable that the OP tagged the code as C++. Passing a 2D array to a function expecting a pointer to pointer is not valid in either C or C++. – Peter Feb 22 '20 at 22:26

1 Answers1

1

Your declaration should look like this:

#include <stdio.h>

void Printarr(int col, int arr[][col]){
    for(int i = 0; i < col; i++){
        for(int j = 0; j < col; j++)
            printf("%d ", arr[i][j]);
        printf("\n");
    }
}

int main(){
    int col = 10;
    int abc[col][col];
    for(int i = 0; i < col; i++){
        for(int j = 0; j < col; j++){
            abc[i][j]=0;
        }
    }
    Printarr(col,abc);
    return 0;
}

Your function argument is a pointer to a pointer but you only give it a normal pointer.

HWilmer
  • 458
  • 5
  • 14