Char question

Is the following statements correct? Why?

char s[] = "Greetings";

s = “Greetings";
The second one is not correct, because you cannot assign raw arrays to arrays.
Thanks, but how about in this case.


char* s = "hello";

s = “how are you?”;

It is correct?
This is "correct" because the pointer value s is assigned the address of the string constant "how are you?", which is allocated somewhere in memory by the compiler.
No, because you cannot (anymore) initialize pointers to non-const char with string literals.
Use const char* s = "hello";
Last edited on
Cubbi's right. I typed too fast.
Thanks :)
Topic archived. No new replies allowed.