I am almost a beginner in C and I want to allocate a 2 dimensional array, change it, reallocate it and print it. Both of the answers with the code were useful.Now the code is:
main()
{
int i, j, L , **lp ;
scanf("%i" , &L );
lp = calloc(L , sizeof(*lp) );
for(i=0 ; i<L ; i++)
lp[i] = calloc( L , sizeof( *(lp[i])) );
for(i=0 ; i<L ; i++)
{
for(j=0 ; j<L ; j++ )
{
lp[i][j]=0;
printf("%i " , lp[i][j] );
}
printf("
");
}
free( lp );
return(0);
}
See Question&Answers more detail:os