Re: confused with sizeof and pointers
From: Eric Sosman (eric.sosman_at_sun.com)
Date: 03/17/05
- Next message: vijay: "Re: New to C please help nice and easy!!"
- Previous message: Bonj: "high-end generic binary tree"
- In reply to: vijay: "confused with sizeof and pointers"
- Next in thread: Keith Thompson: "Re: confused with sizeof and pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: vijay: "Re: New to C please help nice and easy!!"
- Previous message: Bonj: "high-end generic binary tree"
- In reply to: vijay: "confused with sizeof and pointers"
- Next in thread: Keith Thompson: "Re: confused with sizeof and pointers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|