Can anyone explain what is the wrong of the code below? İf I give the "line" variable as 1,2,3 or 4, it runs correctly. But after 4 it just shows a count of row correctly, the count of columns is not correct.
output of dev-c/c++ on windows >> "return value 3221225477"
output of gcc on mac >> "Segmentation fault: 11"
#include<stdio.h>
#include<stdlib.h>
int main(){
int **matris;
int size;
int i, j;
printf( "Size >> " );
scanf( "%d", &size );
matris = (int **)malloc( size * sizeof(int) );
if( matris == NULL )
printf( "It's required more memory'!" );
for( i = 0; i < size; i++ ) {
matris[i] = malloc( size * sizeof(int) );
if( matris[i] == NULL )
printf( "It's required more memory'!!" );
}
for( i = 0; i < size; i++ ) {
for( j = 0; j < size; j++ ){
matris[i][j]=i+1;
printf( "%d ", matris[i][j] );
}
printf( "\n" );
}
for( i = 0; i < size; i++ ) {
free( matris[i] );
}
free( matris );
return 0;
}