#include<stdio.h>
int main()
{
int i,j;
int ct=0;
int *a[3];
for( i=0;i<3;i++)
{
a[i]=(int **)malloc(sizeof(int)*4);
for(i=0;i<3;i++){
for(j=0;j<4;j++)
a[i][j]=ct++;
printf("%d",a[i][j]);
}
}
}
On Sat, Jul 2, 2011 at 12:13 AM, Anika Jain <anika.jai...@gmail.com> wrote:

> do we need to add m in each a[i]?? shudnt it be a[i] = a+ n*i?? i think i m
> doing a silly mistake.. bt plz tell me..
>
>
> On Thu, Jun 30, 2011 at 7:41 AM, Dave <dave_and_da...@juno.com> wrote:
>
>> @Rizwan: Not completely. What if ROW in your code is a variable (not a
>> constant) that is not known until run time? Then you need to
>> dynamically allocate space for your arr2D as well. So, contradicting
>> my earlier "No" response, maybe something like this would work to
>> allocate an array a with m rows and n columns:
>>
>> int* a = (int*)malloc( m * ( sizeof(int*) + n * sizeof(int) ) );
>> for( i = 0 ; i < m ; ++i )
>>    a[i] = a + m + i * n;
>>
>> Dave
>>
>> On Jun 29, 4:41 pm, rizwan hudda <rizwanhu...@gmail.com> wrote:
>> > I have solved this using one malloc find the code inhttp://
>> ideone.com/BV9Kj
>> >
>> >
>> >
>> >
>> >
>> > On Thu, Jun 30, 2011 at 1:20 AM, Piyush Sinha <ecstasy.piy...@gmail.com>
>> wrote:
>> > > ohh sorry....my bad...i didnt read the whole question..i just read the
>> > > subject...:P
>> >
>> > > i think its not possible if u want other than hary's solution...
>> >
>> > > On 6/30/11, Apoorve Mohan <apoorvemo...@gmail.com> wrote:
>> > >> @piyush: only one call to malloc...ur sol has 2
>> >
>> > >> On Thu, Jun 30, 2011 at 12:58 AM, Piyush Sinha
>> > >> <ecstasy.piy...@gmail.com>wrote:
>> >
>> > >>> int **p;
>> > >>> p = (int **)malloc(sizeof(int *)*row);
>> > >>> for(i = 0;i<row;i++)
>> > >>>       p[i] = (int *)malloc(sizeof(int)*column);
>> >
>> > >>> On 6/30/11, Apoorve Mohan <apoorvemo...@gmail.com> wrote:
>> > >>> > though thankx :)
>> >
>> > >>> > On Thu, Jun 30, 2011 at 12:44 AM, Apoorve Mohan
>> > >>> > <apoorvemo...@gmail.com>wrote:
>> >
>> > >>> >> @above: man i need a 2d array not a 1d array...
>> >
>> > >>> >> On Thu, Jun 30, 2011 at 12:38 AM, hary rathor
>> > >>> >> <harry.rat...@gmail.com>wrote:
>> >
>> > >>> >>> #include<stdlib.h>
>> >
>> > >>> >>> int main ()
>> > >>> >>> {
>> > >>> >>>     int *mat;
>> > >>> >>>     int i,j;
>> > >>> >>>     int ROW=4;
>> > >>> >>>     int COL=3;
>> > >>> >>>     int k=0;
>> > >>> >>>     mat=(int *)malloc(ROW*COL*sizeof(int));
>> >
>> > >>> >>>    for(i=0;i<ROW;i++)
>> > >>> >>>    for(j=0;j<COL;j++)
>> > >>> >>>    mat[i*COL+j]=++k;
>> >
>> > >>> >>>    for(i=0;i<ROW;i++)
>> > >>> >>>    for(j=0;j<COL;j++)
>> > >>> >>>    printf("%d,",mat[i*COL+j]);
>> >
>> > >>> >>>     return 0;
>> >
>> > >>> >>> }
>> >
>> > >>> >>>  --
>> > >>> >>> You received this message because you are subscribed to the
>> Google
>> > >>> Groups
>> > >>> >>> "Algorithm Geeks" group.
>> > >>> >>> To post to this group, send email to algogeeks@googlegroups.com
>> .
>> > >>> >>> To unsubscribe from this group, send email to
>> > >>> >>> algogeeks+unsubscr...@googlegroups.com.
>> > >>> >>> For more options, visit this group at
>> > >>> >>>http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > >>> >> --
>> > >>> >> regards
>> >
>> > >>> >> Apoorve Mohan
>> >
>> > >>> > --
>> > >>> > regards
>> >
>> > >>> > Apoorve Mohan
>> >
>> > >>> > --
>> > >>> > You received this message because you are subscribed to the Google
>> > >>> > Groups
>> > >>> > "Algorithm Geeks" group.
>> > >>> > To post to this group, send email to algogeeks@googlegroups.com.
>> > >>> > To unsubscribe from this group, send email to
>> > >>> > algogeeks+unsubscr...@googlegroups.com.
>> > >>> > For more options, visit this group at
>> > >>> >http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > >>> --
>> > >>> *Piyush Sinha*
>> > >>> *IIIT, Allahabad*
>> > >>> *+91-8792136657*
>> > >>> *+91-7483122727*
>> > >>> *https://www.facebook.com/profile.php?id=100000655377926*
>> >
>> > >>> --
>> > >>> You received this message because you are subscribed to the Google
>> Groups
>> > >>> "Algorithm Geeks" group.
>> > >>> To post to this group, send email to algogeeks@googlegroups.com.
>> > >>> To unsubscribe from this group, send email to
>> > >>> algogeeks+unsubscr...@googlegroups.com.
>> > >>> For more options, visit this group at
>> > >>>http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > >> --
>> > >> regards
>> >
>> > >> Apoorve Mohan
>> >
>> > >> --
>> > >> You received this message because you are subscribed to the Google
>> Groups
>> > >> "Algorithm Geeks" group.
>> > >> To post to this group, send email to algogeeks@googlegroups.com.
>> > >> To unsubscribe from this group, send email to
>> > >> algogeeks+unsubscr...@googlegroups.com.
>> > >> For more options, visit this group at
>> > >>http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > > --
>> > > *Piyush Sinha*
>> > > *IIIT, Allahabad*
>> > > *+91-8792136657*
>> > > *+91-7483122727*
>> > > *https://www.facebook.com/profile.php?id=100000655377926*
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups "Algorithm Geeks" group.
>> > > To post to this group, send email to algogeeks@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> > > For more options, visit this group athttp://
>> groups.google.com/group/algogeeks?hl=en.
>> >
>> > --
>> > Thanks and regards
>> > Rizwan A Huddahttp://sites.google.com/site/rizwanhudda2- Hide quoted
>> text -
>> >
>> > - Show quoted text -
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> 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 algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
SOURABH JAKHAR,(CSE)(3 year)
ROOM NO 167 ,
TILAK,HOSTEL
'MNNIT ALLAHABAD

The Law of Win says, "Let's not do it your way or my way; let's do it the
best way."

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to