You can make use of the array name to get the starting address of the
array...

Since you allocate memory statically( arr[5] ) the compiler reserves 5
locations to store 5 integer values. The size will not exceed 20 (if each
integer occupies 4 bytes) and the locations are reserved and maximum number
of locations is a constant (5 here) throughout the program execution, where
as in case of pointers you can allocate memory dynamically so there is no
upper bound for the number of elements to store.

Hope u got it.. :)

On 3 August 2011 14:42, Arun Vishwanathan <[email protected]> wrote:

> hi i have a slight confusion..i got the above explanation but i have a
> doubt as in when u say int arr[5], arr is also the pointer to the first
> element of the array right?..so size(arr) shudnt be the size of pointer
> (which is int 4 byte address it holds of the first array element?) ..is it
> not interpreted this way?....and sizeof(&arr) looks like address of the
> pointer itself which also will be int (4 bytes)??
>
>
> On Wed, Aug 3, 2011 at 5:59 AM, Thavasi Subramanian 
> <[email protected]>wrote:
>
>> Ur compiler might have supported 4 bytes to store an integer value....
>>
>> sizeof(arr)
>> Since the array is capable of holding 5 integer values at the most total
>> byes required=4*5=20 byte.
>>
>> Now, sizeof(&arr)
>> Here you referred the starting address of the array and the addresses are
>> integer values the output is as same as sizeof(int)=4 byte
>>
>> So you get 20 4 as output
>>
>> Hope you got it.... :)
>>
>>
>> On 3 August 2011 01:45, Anuj kumar <[email protected]> wrote:
>>
>>> #include<stdio.h>
>>> #include<conio.h>
>>> int main()
>>> {
>>>  int arr[5];
>>>  printf("%d %d\n",sizeof(arr),sizeof(&arr));
>>>     getch();
>>>     return 0;
>>> }
>>>
>>> o/p  20    4
>>>
>>> anybody can tell me how 20 is coming plzz
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> Thavasi
>>
>> --
>> 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.
>



-- 
Thavasi

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