Re: [algogeeks] Re: memory allocation question

2011-09-03 Thread Nitin Garg
 int(*p)[col];

Here, p is a pointer to an array of 4 integers.
Size of *p is 4X4 = 16.

 p=(int(*)[col])malloc(row*sizeof(*p));

here clearly 3X 16  = 48 bytes of memory is being allocated.


On Sat, Sep 3, 2011 at 9:14 PM, piyush agarwal  wrote:

> no. of rows is 3
> size of (*p) is 12
> then how can 48 be the no. of bytes ??
>
> On Sat, Sep 3, 2011 at 8:32 AM, Deepak Garg wrote:
>
>> +1
>>
>>
>> On Sat, Sep 3, 2011 at 8:57 PM, Ankuj Gupta  wrote:
>>
>>> p is a pointer to an array of 4 integers. So when you do (int(*)
>>> [col])malloc(row*sizeof(*p)) total of 48 bytes is allocated as
>>> sizeof(*p) is 12 bytes.
>>>
>>> On Sep 3, 4:14 pm, rohit  wrote:
>>> > how many bytes are allocated by following code?
>>> >
>>> > #include
>>> > #define col 4
>>> > #define row 3
>>> >
>>> > int main()
>>> > {
>>> > int(*p)[col];
>>> > p=(int(*)[col])malloc(row*sizeof(*p));
>>> >
>>> > return 0;
>>> >
>>> > }
>>> >
>>> > please explain answer?
>>>
>>> --
>>> 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.
>>>
>>>
>>
>>
>> --
>> U.D.I.T
>>
>> Sent by Nokia OVI (c)
>>
>>  --
>> 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 Agarwal
> Final Year Undergraduate
> Department of Computer Engineering
> Malaviya National Institute of Technology
> Jaipur
>
> --
> 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.
>



-- 
Nitin Garg

"Personality can open doors... but only Character can keep them open"

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



Re: [algogeeks] Re: memory allocation question

2011-09-03 Thread piyush agarwal
no. of rows is 3
size of (*p) is 12
then how can 48 be the no. of bytes ??

On Sat, Sep 3, 2011 at 8:32 AM, Deepak Garg  wrote:

> +1
>
>
> On Sat, Sep 3, 2011 at 8:57 PM, Ankuj Gupta  wrote:
>
>> p is a pointer to an array of 4 integers. So when you do (int(*)
>> [col])malloc(row*sizeof(*p)) total of 48 bytes is allocated as
>> sizeof(*p) is 12 bytes.
>>
>> On Sep 3, 4:14 pm, rohit  wrote:
>> > how many bytes are allocated by following code?
>> >
>> > #include
>> > #define col 4
>> > #define row 3
>> >
>> > int main()
>> > {
>> > int(*p)[col];
>> > p=(int(*)[col])malloc(row*sizeof(*p));
>> >
>> > return 0;
>> >
>> > }
>> >
>> > please explain answer?
>>
>> --
>> 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.
>>
>>
>
>
> --
> U.D.I.T
>
> Sent by Nokia OVI (c)
>
>  --
> 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 Agarwal
Final Year Undergraduate
Department of Computer Engineering
Malaviya National Institute of Technology
Jaipur

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



Re: [algogeeks] Re: memory allocation question

2011-09-03 Thread Deepak Garg
+1

On Sat, Sep 3, 2011 at 8:57 PM, Ankuj Gupta  wrote:

> p is a pointer to an array of 4 integers. So when you do (int(*)
> [col])malloc(row*sizeof(*p)) total of 48 bytes is allocated as
> sizeof(*p) is 12 bytes.
>
> On Sep 3, 4:14 pm, rohit  wrote:
> > how many bytes are allocated by following code?
> >
> > #include
> > #define col 4
> > #define row 3
> >
> > int main()
> > {
> > int(*p)[col];
> > p=(int(*)[col])malloc(row*sizeof(*p));
> >
> > return 0;
> >
> > }
> >
> > please explain answer?
>
> --
> 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.
>
>


-- 
U.D.I.T

Sent by Nokia OVI (c)

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