Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Arrays & Po...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 25444 of 28234
Post > Topic >>

Re: Arrays & Pointers

by David Thompson <dave.thompson2@[EMAIL PROTECTED] > Apr 21, 2008 at 01:33 AM

On Wed, 09 Apr 2008 12:34:43 +0500, arnuld <arnVuld@[EMAIL PROTECTED]
>
wrote:

> I am trying hard to understand the Arrays & Pointers relation****p. Tell
> me if I am wrong: 
> 
> 
> char a[] =  "blah blah";
> char *p  =  "blah blah";
> 
> 
>                    ----------------------
> ARRAY             |    |    |   |   |    |     
>                   |    |    |   |   |    |     
>                    ----------------------
> 
>                    ----------------------
>  p ---- ----- ----|->  |    |   |   |    |     
>                   |    |    |   |   |    |     
>                    ----------------------
> 
> this is the difference between an array and pointer to a string. Arrays
&
> Pointers are *not* interchangeable, they are *not* equal. When we pass
an
> array to a function, we are faking a pointer-phenomenon in reality
because
> arrays can not be passed to functions, when we pass an array as a
> parameter to a function, it immediately decays into a pointer to its 1st
> element and then we can access the subsequent elements using
> pointer-arithmetic. That's all we got about Arrays and Pointers
relation.
> Except this they have nothing in common.
> 
I think you've got the idea, but:

- I would be careful about using 'equal'. Pointers and arrays are
different things, but they only way in C to determine equality of two
things is an expression using the == operator, and _in an expression_
an array turns into a pointer which when compared to another pointer
can indeed be equal. Since your sig refers to lispmachine, I'll point
out that LISP makes a similar distinction between EQ and EQUAL.

They actually are interchangeable _sometimes_, but not all. I like to
say 'not identical', or just 'not the same'.

- also, I wouldn't say that passing an array to a function, or in most
other uses, is 'faking' a pointer. The array (lvalue) is _converted_
to a pointer (rvalue), which is then just as good a pointer value as
any other. Maybe 'creating' or 'producing'. Or the general term for
the result of any expression/operation, 'yielding'.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 




 3 Posts in Topic:
Arrays & Pointers
arnuld <arnVuld@[EMAIL  2008-04-09 12:34:43 
Re: Arrays & Pointers
Philip Potter <pgp@[EM  2008-04-09 11:51:32 
Re: Arrays & Pointers
David Thompson <dave.t  2008-04-21 01:33:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 17:34:27 CST 2008.