<DIV>
<DIV>hi all,<BR><BR>The way to dynamically allocate a 2D array is :<BR><BR><BR>int a(*)[5];<BR><BR>a=(int (*)[5])malloc(sizeof(int)*5);<BR><BR><BR>This will create array of pointer to arrays.<BR><BR>We can access elements as a 2D array<BR>a[1][1] with access particular element.<BR><BR><BR><BR>Question:<BR>1.<BR>After allocating space for pointers, is it not the case that i need to allocate space for the array they are pointing to?, as we usually do for a pointer to point to array of elements.<BR><BR>2.<BR>Is my way of freeing ok<BR><BR>for(i=0;i<5;i++)<BR>free(a[i]);<BR><BR>Because it will free the pointers , what about the elements associated with those pointers.
<DIV>hi all,<BR><BR>The way to dynamically allocate a 2D array is :<BR><BR><BR>int a(*)[5];<BR><BR>a=(int (*)[5])malloc(sizeof(int)*5);<BR><BR><BR>This will create array of pointer to arrays.<BR><BR>We can access elements as a 2D array<BR>a[1][1] with access particular element.<BR><BR><BR><BR>Question:<BR>1.<BR>After allocating space for pointers, is it not the case that i need to allocate space for the array they are pointing to?, as we usually do for a pointer to point to array of elements.<BR><BR>2.<BR>Is my way of freeing ok<BR><BR>for(i=0;i<5;i++)<BR>free(a[i]);<BR><BR>Because it will free the pointers , what about the elements associated with those pointers.</DIV><!-- / message --></DIV><!-- / message --></DIV><p>__________________________________________________<br>Do You Yahoo!?<br>Tired of spam? Yahoo! Mail has the best spam protection around <br>http://mail.yahoo.com