2 malloc():
int **a=(int **)malloc(sizeof(int *)*nrows);
for(i=0;i<nrows;i++)
a[i]=(int *)malloc(sizeof(int)*ncols);
using only 1 malloc:
int **a=(int **)malloc(sizeof(int *)*nrows+(nrows*ncols)*(sizeof(int)));
for(i=0;i<nrows;i++)
{
a[i]=(int*)(a+nrows+i*ncols);
}
On Fri, Jun 29, 2012 at 4:46 PM, rahul r. srivastava <
[email protected]> wrote:
> implement a 2d matrix using only 2 mallocs.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/s4vvxtO2yVsJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.