I have the following code:
#include <iostream>
#include <string>
using namespace std;
string combine(string a, string b, string c);
int main() {
char name[10] = {'J','O','H','N','\0'};
string age = "24";
string location = "United Kingdom";
cout << combine(name,age,location);
return 0;
}
string combine(string a, string b, string c) {
return a + b + c;
}
This compiles fine with no warnings or errors despite the combine function expecting a string and receiving a char array, is this because a string is stored as a char array?
char name[10] = {'J','O','H','N','\0'};can be written much more simply aschar name[10] = "JOHN";.