c++ - Is text in code char or const char? -


possible duplicate:
string literals vs const char* in c

why can this?

void foo(char * cstr) {     ... } 

and in code

foo("some text"); 

shouldnt "some text" of type const char * ?

if char *, means can modify it?

yes, should const.

in c++03, allowed omit const backward compatibility c, 2 caveats:

  • you still not allowed modify data. yes, highly confusing. that's why leaving out const deprecated. ideally plain disallowed (and, in c++11 onwards, is).

  • if have compiler's warning level set properly, warned when trying this. if have compiler's error level set strictly treated error.


Comments

Popular posts from this blog

jQuery Ajax Render Fragments OR Whole Page -

javascript - Iterate over array and calculate average values of array-parts -

java - Simple Command Line calculator -