1.Array name is nothing but a const pointer to the first element of an
array.
2.subscripting of an array can be visualized as incrementing a
pointer . Pointer always increments by the size of the type of data it
holds.
3. so, always sizeof(arr) is the sizeof a pointer  , and sizeof(*arr)
is the sizeof(1) i.e size of the first element. it is an integer
here.
4. Pointers size and integers size are same in most compilers ( dont
think of far pointers now) . so it resulted in 1 despite of the no.of
elements in that array.

Hope i made it more clear  :)

On Jul 25, 12:01 am, tarak mehta <tarakmeht...@gmail.com> wrote:
> void hell(int arr[]);
> main()
> {
>        int arr[]={1,2,3,4,5};
>        hell(arr);}
>
> void hell(int arr[])
> {
> printf("%d",sizeof(arr)/sizeof(*arr));}
>
> even this gives 1 !!
> @manjunath ur idea seems correct..but could u plz elaborate a bit
>
> On Sat, Jul 24, 2010 at 10:51 PM, Manjunath Manohar <
>
>
>
> manjunath.n...@gmail.com> wrote:
>
> > when arrays are passed as arguments to a function,the starting address of
> > the array is passed like a pointer,
> > thus sizeof(arr)=2..thus 2/2=1..this is the precise reason for always
> > specifying the column length in the definition of function when functions
> > have arrays as one of the arguments..
>
> > Hope i made any sense.. :)
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algoge...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@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