Re: confused with sizeof and pointers

From: Eric Sosman (eric.sosman_at_sun.com)
Date: 03/17/05


Date: Thu, 17 Mar 2005 13:26:53 -0500


vijay wrote:
> Hello,
>
> I am new to C Programming and just started reading K&R. I was about to
> finish the pointers chapter but got very confused with:
>
> 1. int arr[10];
>
>>>From what I have read, arr is a pointer to the first int and &arr is a
> pointer to the whole array of 10 ints. Then why does sizeof(arr) gives
> 40 while sizeof(&arr) gives 4. Shouldn't is be the other way around.
>
> 2. int arr[2][2]={{1,2},{3,4}};
> printf("%u %u",arr,*arr);
>
> produces the same output(base address). But haven't we dereferenced arr
> in the second case. I mean, arr is an address to the base of the array
> and putting a star in front of should give us the value there.

    Section 6 of the comp.lang.c Frequently Asked
Questions (FAQ) list

        http://www.eskimo.com/~scs/C-faq/top.html

may help you understand this better. Read it, and
post again if you are still confused.

-- 
Eric.Sosman@sun.com


Relevant Pages

  • Re: array
    ... > It is an array of one TRGBQUAD. ... > (pointers to) variable size arrays. ... reading another post you've referenced similarly, on this same thread, I am ... Anyway back to this dynamic element of these two types of "hacks" ...
    (borland.public.delphi.language.objectpascal)
  • need help with list of lists ( multi dimensional array)
    ... Hi - looking for pointers or links to resources ... ... I am reading in a text file - lines are ... It seems to be that an array would work great here, ...
    (comp.lang.perl.misc)
  • Re: [C] functions and 2D arrays?
    ... >to arrays of arrays of int, when you could be passing pointers ... >to arrays of int. ... to array" is rather out of the ordinary. ... feels more "natural" after you've been reading and writing C and C++ ...
    (alt.comp.lang.learn.c-cpp)
  • confused with sizeof and pointers
    ... finish the pointers chapter but got very confused with: ... int arr; ... But haven't we dereferenced arr ... arr is an address to the base of the array ...
    (comp.lang.c)
  • Re: Differance between Array and Pointers
    ... Well, except that arrays tend to be much larger than pointers, and the ... An array is a contiguous region of memory containing N elements of M ... indexing vs. a loop). ...
    (comp.arch.embedded)