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 <
> >rainerweiku...@virginmedia.com> 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

Uppps :)
_______________________________________________
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng

Reply via email to