473,563 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Arrays & Pointers

On Wed, 09 Apr 2008 12:34:43 +0500, arnuld <ar*****@ippiVm ail.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.ne t
Jun 27 '08 #1
0 1286

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

Similar topics

2
2596
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 is in a new state. The update process depends upon the entire system state prior to updating...that is, a single array cannot be serially updated,...
21
3901
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 "browse" it). So I expected that when I run this program, I get both c1.A and c2.A pointing to the same address, and changing c1.A means that also...
79
3347
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 Shocking Truth: C Arrays and Pointers Are NOT the Same! 9: More about Arrays 10: More about Pointers What blows me out of the water is the fact...
9
1621
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 why the output looks the way it does, in particular, with all the symmetry in arguments, why one sees apple but not argv. This program was designed...
8
2240
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 that a declaration like: int intArray means that there is an array of pointers to int with a size of 5, each of whose elements is an array of int with...
36
2810
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
2001
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 2D array and iterate through copy contents from arrays into this new 2D array. Example: int ** someArray; int * topRow; int * bottomRow;
17
3226
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: ================================================================================ /* A function that returns a pointer-of-arrays to the calling function. */ #include <stdio.h> int *pfunc(void);
4
2494
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
7580
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6244
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5481
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.