@abhishek.... its wrong as arr1 is just a pointer o int and sizeof(arr1)
will always be 4 bytes(size of a pointer) regardless of number of bytes
allocated to it on heap....

On Tue, Jul 3, 2012 at 3:14 PM, Abhishek Sharma <[email protected]>wrote:

> arr1 = (int *)malloc(sizeof(int) * ncols);    // memory allocated for 1st
> row
> arr2 = (int **)malloc(sizeof(arr1) * nrows);
>
> I haven't tried it.So,please correct me if i am wrong
>
>
> On Mon, Jul 2, 2012 at 12:55 PM, Rishabh Agarwal <[email protected]>wrote:
>
>>
>>     nrows: number of rows
>>     ncols: number of columns
>>
>>     int **arra = (int **)malloc( sizeof(int*) * nrows );
>>     int *ar = (int *)malloc( sizeof(int) * nrows * ncols );
>>     for( int a = 0; a < nrows; a ++ ) {
>>         arra[a] = ar + ncols * a;
>>     }
>>
>>     now index of array i and j can be accessed as arra[i][j]
>>
>>
>>
>> On Friday, June 29, 2012 4:46:18 PM UTC+5:30, rahul r. srivastava 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/-/Pr2cEtta_LsJ.
>>
>> 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.
>>
>
>
>
> --
> Abhishek Sharma
> Under-Graduate Student,
> PEC University of Technology
>
>  --
> 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.
>

-- 
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.

Reply via email to