Home > Back-end >  For help! Char * C does not exist?
For help! Char * C does not exist?

Time:10-02


You see...? Why can't use char * type the character pointer?

CodePudding user response:

Because the string constant area immediately "hello" is not allowed in the modified,
You use a char * pointer pointing to it is not so safe, because the char * pointer can take changes the value of the point to
Actually is a kind of grammatical constraints, essentially nothing can point to,
You can use some SAO let he points to the operation, just point to one thousand you don't watch out, try to change the string constants are cool,

So the grammar, or compiler constraint you don't want this dry,

CodePudding user response:

This constraint is a compiler, compiler can so old, you can add a const, it is safer, essentially the memory also won't allow you to modify

CodePudding user response:

Just like int& R=42; Statement is wrong, as personal understanding compiler fear you change the value of the constants in the same way char * c="hello" is the same, you can use the safe casting char * c=const_cast & lt; Char * & gt; (" hello ");
  • Related