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 <[email protected]> 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 <[email protected]>wrote:
>
>> +1
>>
>>
>> On Sat, Sep 3, 2011 at 8:57 PM, Ankuj Gupta <[email protected]> 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 <[email protected]> wrote:
>>> > how many bytes are allocated by following code?
>>> >
>>> > #include<alloc.h>
>>> > #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 [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.
>>>
>>>
>>
>>
>> --
>> 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 [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.
>>
>
>
>
> --
> 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 [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.
>



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