In this code, we made a const char pointer id, as it is a char so it should store only one element address. but in default constructor we assigned, "NULL" to that id, how is that id is holding 4 char? and in parameterized constructor we pass i[] array and assign the value to id, same again how char id is holding complete array? further why we need const char?
class Employee
{
public:
string name;
const char *id;
int age;
long salary;
Employee ()
{
name = "NULL";
id = "NULL";
age =0;
salary = 0;
};
// Employee(string n, char id[], int a, long s): name(n), id(id), age(a), salary(s)
// {};
Employee (string n,const char i[], int a, long s) //const use krne k baighar warning a rhe
{
name = n;
id = i;
age = a;
salary = s;
};
void getData()
{
cout<< "Employee ID: "<< id <<endl;
cout<< "Employee Name: "<< name <<endl;
cout<< "Employee Age: "<< age <<endl;
cout<< "Employee Salary: "<< salary <<endl;
};
};
I am confused that if id is char then how it is holding a string literal of 5 character. CHAR type can store only single character, but if i am making it a pointer then it is holding many character. Please clear this point, i am very confused as how it is working.