What should the return type of the following function be?
[returnType] printName(string fName, string lName){
cout << fName << " " << lName << endl;
}
ANSWER: For this given function name printName() return type should be void because in this function no operations are performed and not returning anything from it simply you are printing the first name and last name so here return type should be void. Below is the code and output for your reference please do upvote or comment on it if you still have any doubt.
CODE:
#include <iostream>
using namespace std;
void printName(string fName, string lName){
cout << fName << " " << lName << endl;
}
int main()
{
string fName,lName;
cout<<"Enter first name and last name:";// Here I am taking
input for first name and last name.
cin>>fName>>lName;
printName(fName,lName);
return 0;
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.