Auteur: aitor_czr Datum: Aan: KatolaZ CC: dng Onderwerp: Re: [DNG] Making sense of C pointer syntax.
On 03/31/16 16:07, KatolaZ wrote: > On Thu, Mar 31, 2016 at 03:58:49PM +0200, aitor_czr wrote:
>
> [cut]
>
>>> > >On Wed, Mar 30, 2016 at 6:04 PM, Rainer Weikusat <
>>> > >rainerweikusat@???> wrote:
>>> > >
>>> > >There's one
>>>> > >>important difference:
>>>> > >>
>>>> > >>char chars[] = "12345";
>>>> > >>
>>>> > >>cause the compiler to reserve six bytes (five chars + terminating 0) in
>>>> > >>some location the program can write to. Afterwards,
>>>> > >>
>>>> > >>*chars = R;
>>>> > >>
>>>> > >>could be used to change the string to R2345.
>> >
>> >This is because
>> >
>> >*chars <---> *(chars+0) <---> chars[0]
>> >
>> >are analogous. So, chars[0] changes from 1 to R.
>> >
> Again. being pedantic here the assignment:
>
> *chars = R;
>
> assigns the value of the variable R (which should be a char) to the
> first byte of the memory area pointed by chars. If you we want to
> change the first character of the string into the letter 'R', we
> should write:
>
> *chars = 'R';
>
> Notice the (sometimes misleading and) subtle difference between single
> quotes ('), which are used for character constants, and double quotes
> (") which are used to delimit strings (i.e., they are the syntactic
> sugar around constant arrays of char).
>
> My2Cents
>
> KatolaZ