Barry Schwarz於 2011年12月18日星期日UTC+8上午2時10分09 寫道:
> On Sat, 17 Dec 2011 08:51:33 -0800 (PST), 88888 Dihedral
> <dihedr...@googlemail.com> wrote:
>
> >On Wednesday, December 7, 2011 8:22:56 PM UTC+8, curixinfotech wrote:
> >> hi
> >> my Q is on the c language tell me now why c has pointers.
> >> parshant
> >>
> >>
> >> --
> >> curixinfotech
> >> ------------------------------------------------------------------------
> >> curixinfotech's Profile: http://forums.yourdomain.com.au/member.php?userid=134
> >> View this thread: http://forums.yourdomain.com.au/showthread.php?t=3319
> >
> >OK, I'll explain how to use a pointer in C without any knowledge in the
> >hardware or assembly here.
> >//
> >int i;
> >int a[3]={ 1,2,3} ; // an array of 3 integers
> >int* ptr1; // Note the star should be right after int, not initialize
> >int* ptr2; // not initialized
> >
> >ptr1=a; // Read this as to make ptr1 to be an alias of a.
>
> If that were true, the sizeof(a) and sizeof(ptr1) would be equal\
Why do you care about the size of an array declared on the stack?
Everything on the stack is to be popped out in the exit of a function in C.
But a pointer allocated in the heap is different.
> which, in the general case, they are not. ptr1 is simply a pointer
> that points to the start of a. Even though they share some
> similarities in the language syntax, a pointer is a completely
> different type than an array. Calling one an alias of the other just
> breeds unnecessary confusion.
A pointer defines an alias to a variable. Don't you get it in C or assembly?