Just wanted to know why we use asterisk with return in the following code,,whats the logic of it.
Code:void setname()
{
cin>>name;
}
char getname()
{
return *name;
}
Printable View
Just wanted to know why we use asterisk with return in the following code,,whats the logic of it.
Code:void setname()
{
cin>>name;
}
char getname()
{
return *name;
}
Presumably name is a char array? In that context, name by itself would then be taken to represent the address of the first character of array (a char pointer). In order to get a specific character (the first character) at an address you must dereference that address/pointer by using the * operator. It seems likely that getname would actually only return the first character of the name entered by the setname function.
yeah name is a char array,, it dint only return the firsl character,,it returns the whole string,,