#string concatenation
27 messages · Page 1 of 1 (latest)
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
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
string2 is a const char*, q is not.
so i must either remove const from string2 or use string2 as a pointer itself?
You'd have to remove const, you've declared string2 as const meaning you can't increment or decrement it
char const *q = string2;```
Not true
The const applies to the data that string2 points at
You can increment the pointer
And not the pointer?
I understand now, thank you!
That would be char *const
Ohhhhh gotcha, my bad! 🫡
Np
there's a nice trick about readability
instead of const char * flip the order of the const and char: char const *
one makes array constant and another makes pointer constant
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
@zealous cypress Has your question been resolved? If so, type !solved :)