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

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

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

iphone - Using nested NSDictionary with Picker -