on-internet
← Community

Why can't I pass a C-style multidimensional array to a function taking an array of int*?

Stack Overflow ·

#include<stdio.h> void print(int *arr[], int s1, int s2) { int i, j; for(i = 0; i<s1; i++) for(j = 0; j<s2; j++) printf("%d, ", *((arr+i)+j)); } int main() { int a[4][4] = {{0}}; print(a,4,4); } This works in C, but not in C++. error: cannot convert `int (*)[4]' to `int**' for argument `1' to `void print(int**, int, int)' Why does it not work in C++? What change is needed to be made?

Comments

Sign in or sign up to comment and upvote.

No comments yet.