| Battle_Arena Game ~/Desktop/Battle_Aren 1 | cmake-build-debug | PlayerApplications A CMakeLists.txt 2 main.cpp ulı External Libraries O Scratches and Consoles #include "PlayerApplications.h" 2 using namespace std; 3. 4. PlayerApplications::PlayerApplications() { Username = ""; 6 password =
In C++, what is a const char*? And when using const char* would this be well suited or just using string&?
As well as why do I get an error when I try having the username has const char, but I do not get an error when making const char username into a const char* username? What is the reason for this error I am getting?
The use of const char* in C++
const char *p - This is a pointer to a constant character. You cannot change the value pointed by p, but you can change the pointer p itself.
In C++, we can use strings as constant array of characters that is why we use const keyword before char*.
const char *username: We cannot modify the string at later stage in program. We can change username to point something else but cannot change value present at username.
In your program context it is well suited to use const char *username.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps