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
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;
}
0
Mr.Imperfect Thanks very much, I got it.