But,I tried that before but than it gives an error regarding no return statement,When I inserted "return 0;"it works. but should I do this?? as it is a string fuunction, why should I return an integer "0"? By the way, I like the 2nd option.
This makes it sound like you are confused about function declaration (when you precede the function name with a type), and function definitions (when you tell the compiler what the function should do).
You get to declare what TYPE any function is. If you don't wany it to return anything look into the void type. If you want it to return something then return the appropriate data type that you want returned. Just like declaring any variable you can also declare any function in the same manner. You just have to make sure that said function has a return of the type of which you declared it. IE.
Code:
int ThisFunction(){
int a = 10; // just for example purposes
return a; // the function must return a variable that matches it's type.
}
In this manner you can also create any type of function. It can be
Code:
int ThisFunction(){
int Aint = 10;
return Aint;
}
string ThisFunction(){
string Astring = "some arbitrary value";
return Astring;
} // as long as you #include <string>
float ThisFunction(){
float Afloat = 3.14;
return Afloat;
}
double ThisFunction(){
double Adouble = 0.0012353;
return Adouble;
}
On top of that your functions can actually be declared as and return structures and classes that you defined as well. I hope I didn't confuse you, as this is an extremely important aspect to programming in C++.