c++ - Why can I pass a string parameter like this? Is this style safe? -
i passing 2 strings 1 parameter in xcode , using c++. tried in xcode , works. safe on platforms?
#include <iostream> void log_person(const char* name_and_number){ printf("name , number : %s.\n", name_and_number); } int main(int argc, const char * argv[]) { log_person("jim" "123456789"); return 0; }
you passing single string. this
"foo" "bar"
is equivalent to
"foobar"
so call same as
log_person("jim123456789");
this standard c++ , "safe" on conforming implementation. see 2.14.5/13 in c++11 standard:
2.14.5 string literals
...
13 in translation phase 6 (2.2), adjacent string literals concatenated....
Comments
Post a Comment