By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,885 Members | 1,499 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,885 IT Pros & Developers. It's quick & easy.

Re: Arrays & Pointers

P: n/a
On Wed, 09 Apr 2008 12:34:43 +0500, arnuld <ar*****>
I am trying hard to understand the Arrays & Pointers relationship. 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) ||
Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.