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; }
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.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
yeah name is a char array,, it dint only return the firsl character,,it returns the whole string,,