delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/25/09:43:27

Message-Id: <3.0.16.19971125153723.22af8ce2@hem1.passagen.se>
Date: Tue, 25 Nov 1997 15:37:34 -0500
To: DJ Delorie <dj AT delorie DOT com>
From: Peter Palotas <blizzar AT hem1 DOT passagen DOT se>
Subject: Re: pointers &arrays[]
Cc: djgpp AT delorie DOT com
Mime-Version: 1.0

At 08.18 1997-11-25 -0500, you wrote:
>
>> >array == &array
>> This is NOT true. `&array' is a pointer to array, i.e. a pointer to the
>> pointer of the first element in the array.
>
>No, it is true.  Even if they weren't the same, "&array" would be the
>right one, since it's a pointer, and "array" isn't a pointer - it's
>the whole array, like "int" is all 32-bits of an integer.

Okay, apparently I was wrong about this, since I always learned that the
array name was a pointer to the first element of the array.  However, array
!= &array if you pass array to a function as I see it, so it doesn't seem
right to use &array if you want a pointer to the first element in the array.

#include <stdio.h>

char foo[10];

void func(char foo[])
{
	printf("foo = %p, &foo = %p\n", foo, &foo);
}

int main(void)
{
        strcpy(foo, "987654321");
        func(foo);
        return 0;
}

$ ./test.exe
foo = 8c98, &foo = 4c490

-- Peter Palotas alias Blizzar -- blizzar AT hem1 DOT passagen DOT se --

*****************************************************
* A brief description of DJGPP:                     *
* NEVER BEFORE HAS SO FEW DONE SO MUCH FOR SO MANY! *
*****************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019