:: Re: [DNG] Making sense of C pointer…
Top Pagina
Delete this message
Reply to this message
Auteur: Hendrik Boom
Datum:  
Aan: dng
Onderwerp: Re: [DNG] Making sense of C pointer syntax.
On Thu, Mar 31, 2016 at 03:58:49PM +0200, aitor_czr wrote:
> Hi,
>
> On 03/31/16 13:38, Emiliano Marini <emilianomarini82@???> wrote:
> >Besides, * and [] are interchangeable. You can define a string as an array
> >and use it later as a pointer:
> >
> >char s[] = "hola";
> >char x = s[1];     // Here x = 'o'
> >char y = *(s+2);   // Here y = 'l'

> >
> >And vice versa:
> >
> >char *s = "hola";
> >char x = s[0];     // Here x = 'h'
> >char y = *(s+3);   // Here y = 'a'

>
> This is right, and the following sintax are analogous:
>
>      *(p+i) <--->  p[i]


In fact, in the original C specification, p[i] was *defined* to mean *(p+i).

-- hendrik