In C language,
I have an array[3][2];
int i = 0, j = 0;
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
printf("%d", array[i][j]);
}
}
When I use gcc to compile .c file, the error shows:
format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’
How to print an array using C?
The error message seems pretty straight forward. It’s telling you that
array[i][j]is of typeint*, while theprintf()“%d” formatter is expecting an argument of typeint.I’m not sure what you expect to happen here. You haven’t shown us how you declare
array. But, if it’s supposed to be a two-dimensional array ofint, then you declared it wrong.