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

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -