#string concatenation

27 messages · Page 1 of 1 (latest)

zealous cypress
#

Why the warning?

idle cloakBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#

@zealous cypress

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

empty axle
#

string2 is a const char*, q is not.

zealous cypress
fresh phoenix
#

q can be a const pointer

#

You only write to *p so only it must be non-const

empty axle
fresh phoenix
#
char const *q = string2;```
fresh phoenix
#

The const applies to the data that string2 points at

#

You can increment the pointer

empty axle
#

And not the pointer?

zealous cypress
fresh phoenix
empty axle
fresh phoenix
#

Np

#

there's a nice trick about readability

#

instead of const char * flip the order of the const and char: char const *

zealous cypress
#

one makes array constant and another makes pointer constant

fresh phoenix
#

the meaning is exactly the same, but now it's readable from right to left

#

follow these from right to left and see what i mean:

#
// pointer to char
char *p1;

// pointer to const char
char const *p2;

// const pointer to char
char *const p3;

// const pointer to const char
char const *const p4;```
#
char const * const p4; /*
^    ^     ^ ^          *
^    ^     ^ const      *
^    ^     ^            *
^    ^     pointer to   *
^    const              *
^                       *
char                    *
*************************/
#

and so on

#

C's type syntax is kinda wonky, this is one trick that can make it just a little more bearable

idle cloakBOT
#

@zealous cypress Has your question been resolved? If so, type !solved :)