paizza paizza - 1 year ago 56
C++ Question

Which kind of explicit conversion is done here?

This is the code that compile and works in my MVS2015:

#define STRING_TEST "Test String"

using namespace std;

void test(char * str) {
cout << str;

int main ()

I guess that STRING_TEST was converted into a char[11]. Instead, since I pass it without
, it creates a char * pointer? Or what am I missing?

Answer Source

"Test string" is of type const char[12], not char[11] (you forgot '\0').

Your code is equivalent to

test("Test String");

Macros just do a find+replace, so it's not "converted".

Arrays decay into pointers, to here, the char arrays decays into char*. And so test calls it. This however is has been removed as of C++, since const char* != char*.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download