:: Re: [DNG] Making sense of C pointer…
Página Principal
Delete this message
Reply to this message
Autor: Emiliano Marini
Data:  
Para: Steve Litt
CC: dng
Assunto: Re: [DNG] Making sense of C pointer syntax.
char *p;
p="01234"; /* skeezy, but makes the point */

Warning! Here "p" is pointing to nowhere, you don't know which memory
locations are writing to.

char *p;
*p=malloc...*
p="01234"; /* skeezy, but makes the point */


On Mon, Mar 28, 2016 at 12:59 PM, Steve Litt <slitt@???>
wrote:

> On Mon, 28 Mar 2016 14:51:19 +0200 (CEST)
> karl@??? wrote:
>
> > Rainer Weikusat:
> > ...
> > > One thing to note here: Every C pointer is really a pointer to an
> > > array of values, although the size of the array may just be one.
> > ...
> >
> > I thought it was the other way around, a pointer is just an address to
> > some (a single) memory location which can be part of an array
>
> You're both right. A pointer is definitely an address of a single
> memory address of a single byte or char or int or whatever, but that
> single memory address *could* be the first element of an array, thus
> defining the beginning location of the whole array. And of course the
> end of the array must be defined by a second pointer, an integer
> length, or a sentinel value such as '\0' or NULL.
>
> char *p;
> p="01234"; /* skeezy, but makes the point */
> printf("p points to char %c\n", *p);
> printf("p indicates start of string %s\n", p);
>
>
> SteveT
>
> Steve Litt
> March 2016 featured book: Quit Joblessness: Start Your Own Business
> http://www.troubleshooters.com/startbiz
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>