New course! Every coder should learn Generative AI!
Try a free lesson0
Functions and return type
#include <iostream> #include <string> using namespace std; class c1 { public: void fn(int a) { no=a; }; private: int no; }; int main() { c1 obj; obj.fn(10); return 0; } In this program when can i replace return type of main function with void and remove return 0, and does returning integer type have something to do with the function fn's parameter as int?
2 Answers
+ 1
Not 100% sure on the first point, I think C/C++ use int main but the main method in Java, for instance, is void main. Just the way it is :)
The return type is distinct from the parameter type, basically these define what comes out (return type) and what goes into the function (parameter type)
0
Dan Walker yea I haven't seen much void main in c++ unlike in java so I'll go with it, thanks 👍