+ 4
What will happen if I say string main() instead of int main()
c++
13 Answers
+ 11
Hmm no! You can't return a string from main(), it has to be an int. This will give you a compiler error.
+ 10
Because there can be only two ways to terminate a program, succesfully or failure. A string here would not make sense.
+ 8
@Sello, sure thing. But I think you should remove the best answer you gave to Aloisia. lol
+ 8
Thanks!
+ 5
Yeah it is because of the 0, it indicates that the end of the program
+ 4
@Helioform you're right of course
+ 4
you get the error that main has to return int, it's specificated like this
+ 4
but it was a good question, see you got me there too :D
+ 3
you have to return a string at the end of the function, usually there's return 0; at the end and now you would have to write something like return " ";
+ 2
why can't you return a string , does that mean that main runs always as an int or is it because we need the int 0 at the end to safely terminates the program
+ 2
so if I say string main(name){
string name = "selby";
Cout << name;
return name;
} will I get a syntax error? if so why
+ 2
OK thank you, I understand now thanks again for the patient I appreciate it
+ 2
done lol