0

[SOLVED] C/C++: message of the incompatible pointer type

in <stdio.h> #define MAX 12 /*How to stop the message of the warning 'incompatible pointer type'? Help me, please */ int main() { int *p, mat[MAX][MAX]; p = mat; for(int i=0; i<MAX; i++) for(int j=0; j<MAX; j++) mat[i][j] = (i*MAX)+j+1; /*for(int i=0; i<MAX; i++){ for(int j=0; j<MAX; j++) printf("%2d ", *(mat+j)); printf("\n"); } */ printf("%d", *(p+111)); return 0; } https://code.sololearn.com/ct5tSwjFRYej/?ref=app

5th Feb 2021, 4:11 AM
Filipe Duarte Vieira
Filipe Duarte Vieira - avatar
4 Antworten
0
Mr.Imperfect Thanks for answer. I did small something change in your suggestion and it worked: #include <stdio.h> #define MAX 12 int main() { int mat[MAX][MAX]; int* p = (*(mat+0)); for(int i=0; i<MAX; i++) for(int j=0; j<MAX; j++) mat[i][j] = (i*MAX)+j+1; for(int i=0; i<MAX; i++){ for(int j=0; j<MAX; j++) printf("%d ", (*(p+i*MAX+j))); printf("\n"); } return 0; }
5th Feb 2021, 8:23 AM
Filipe Duarte Vieira
Filipe Duarte Vieira - avatar
0
Mr.Imperfect Thanks very much, I got it.
5th Feb 2021, 8:25 AM
Filipe Duarte Vieira
Filipe Duarte Vieira - avatar