473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Re: Arrays & Pointers

On Wed, 09 Apr 2008 12:34:43 +0500, arnuld <ar*****@ippiVmail.com>
wrote:
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) || worldnet.att.net
Jun 27 '08 #1
0 1274

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: J. Campbell | last post by:
I have a class that contains an array of integers that hold the state of my 'system'. The system must be updated periodically. I need to update the whole system at once, at which point the system...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
79
by: Me | last post by:
Just a question/observation out of frustration. I read in depth the book by Peter Van Der Linden entitled "Expert C Programming" (Deep C Secrets). In particular the chapters entitled: 4: The...
9
by: Merrill & Michele | last post by:
What follows is an adaptation of the second program in K&R §5.10. The changes are to elucidate (validate) the difference (sameness) of char * and char**. I cannot for the life of me understand...
8
by: masood.iqbal | last post by:
All this time I was under the illusion that I understand the concept of multi-dimensional arrays well ---- however the following code snippet belies my understanding. I had assumed all along...
36
by: raphfrk | last post by:
I have the following code: char buf; printf("%lp\n", buf); printf("%lp\n", &buf); printf("%lp\n", buf); printf("%lp\n", buf); printf("%d\n", buf-buf);
1
by: Nathan Gilbert | last post by:
I have a function that is returning a 2D array (declared using double pointers) and I want to be able to append a row of data to the beginning and end of this array without having to create a new...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.