Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Why C has Pointers.

Reply
Thread Tools

Re: Why C has Pointers.

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-07-2011
Vincenzo Mercuri <(E-Mail Removed)> writes:
> Il 07/12/2011 13:22, curixinfotech ha scritto:
>> my Q is on the c language tell me now why c has pointers.

>
> here is a short article that can give you a clue as to why and how:
> http://duramecho.com/ComputerInforma...CPointers.html


Do you know of another article that doesn't falsely claim that arrays
are pointers?

In C, an array variable is just a pointer to a chunk of memory
where the elements are stored in order

Arrays *are not* pointers. See section 6 of the comp.lang.c FAQ
<http://c-faq.com>.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Brian
Guest
Posts: n/a
 
      12-07-2011
On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:
> Vincenzo Mercuri <(E-Mail Removed)> writes:
>> Il 07/12/2011 13:22, curixinfotech ha scritto:
>>> my Q is on the c language tell me now why c has pointers.

>>
>> here is a short article that can give you a clue as to why and how:
>> http://duramecho.com/ComputerInforma...CPointers.html

>
> Do you know of another article that doesn't falsely claim that arrays
> are pointers?
>
> In C, an array variable is just a pointer to a chunk of memory where
> the elements are stored in order
>
> Arrays *are not* pointers. See section 6 of the comp.lang.c FAQ
> <http://c-faq.com>.


You are wrong about that, an array access like a[5] actually translates
into *(a+5) - pointer operation.

Cheers Brian
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      12-07-2011
On 12/07/2011 03:00 PM, Brian wrote:
> On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:

....
>> Arrays *are not* pointers. See section 6 of the comp.lang.c FAQ
>> <http://c-faq.com>.

>
> You are wrong about that, an array access like a[5] actually translates
> into *(a+5) - pointer operation.


Did you bother following that link? Before asserting that arrays are
pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
be equal, double the length of the array, and try it again. Also, please
explain why the following does NOT work:

int a[10];
int **p = &a;
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      12-07-2011
On Thursday, December 8, 2011 4:30:58 AM UTC+8, James Kuyper wrote:
> On 12/07/2011 03:00 PM, Brian wrote:
> > On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:

> ...
> >> Arrays *are not* pointers. See section 6 of the comp.lang.c FAQ
> >> <http://c-faq.com>.

> >
> > You are wrong about that, an array access like a[5] actually translates
> > into *(a+5) - pointer operation.

>
> Did you bother following that link? Before asserting that arrays are
> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
> be equal, double the length of the array, and try it again. Also, please
> explain why the following does NOT work:
>
> int a[10];
> int **p = &a;


How a multi-dimensional array in C is implemented? The pointer stores an
address. What a void pointer variable stores( just an address) and points to a value type which can be different in C.





 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-07-2011
88888 Dihedral <(E-Mail Removed)> writes:
> On Thursday, December 8, 2011 4:30:58 AM UTC+8, James Kuyper wrote:
>> On 12/07/2011 03:00 PM, Brian wrote:
>> > On Wed, 07 Dec 2011 11:01:04 -0800, Keith Thompson wrote:

>> ...
>> >> Arrays *are not* pointers. See section 6 of the comp.lang.c FAQ
>> >> <http://c-faq.com>.
>> >
>> > You are wrong about that, an array access like a[5] actually translates
>> > into *(a+5) - pointer operation.

>>
>> Did you bother following that link? Before asserting that arrays are
>> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
>> be equal, double the length of the array, and try it again. Also, please
>> explain why the following does NOT work:
>>
>> int a[10];
>> int **p = &a;

>
> How a multi-dimensional array in C is implemented?

[...]

A multi-dimensional array is simply an array of arrays.

There are data structure that behave like multidimensional arrays using
arrays of pointers. For example, you can have an array of double*
elements, where each element points to the first element of an array of
double. The syntax for accessing an element (a[x][y]) is similar, but
it's not a multidimensional array in the sense that the C standard uses
the term. Implementations using pointers are much more flexible, but
require more housekeeping work to allocate and deallocate memory.

Section 6 of the comp.lang.c FAQ, <http://c-faq.com>, is an excellent
resource.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      12-08-2011
On 12/08/2011 01:39 PM, Vincenzo Mercuri wrote:
> Il 07/12/2011 21:30, James Kuyper ha scritto:
> ...
>> ... Before asserting that arrays are
>> pointers, try comparing sizeof(a) with sizeof(&a[0]); if they happen to
>> be equal, double the length of the array, and try it again. ...

>
> Okay:
>
> #include <stdio.h>
>
> int f(int a[])
> {
> return sizeof(a) == sizeof(&a[0]);
> }

....
> /* just kidding... */


For Brian's benefit, I'll point out that while, in this context, 'a' IS
a pointer, it's also NOT an array, appearances to the contrary
notwithstanding, so it doesn't provide support for his claims. I suspect
that those "appearances to the contrary" are part of the motivation for
such claims.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM
Why, why, why??? =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM



Advertisments