char can only contain 1 character at a time; in this case, it saves your last character, 'x' . char * is a pointer to one or more char objects, and when read correctly, it can also be used as a string. Therefore installation
const char *chName = "Alex"; cout << chName;
should print the whole name.
Another problem is your use of quotes. 'x' stands for a char , and "x" stands for the char s array, known as a string literal.
If there is a function that requires passing char *, you can pass
const char *param = "this is da parameter"; function (param);
or
std::string param = "da parameter";
You can also use an ad.
char chName[] = "Alex";
This would create a local char array (namely, 5 char s, because it adds a null character at the end of the array). Therefore, the call to chName[3] should return 'x' . This can also be passed to cout , like the rest
cout << chName;
EDIT: By the way, you should return int in your main () function. Like 0 .
source share