Functions and return type | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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?

21st Jun 2018, 3:06 PM
Praful M
Praful M - avatar
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)
22nd Jun 2018, 7:24 PM
Dan Walker
Dan Walker - avatar
0
Dan Walker yea I haven't seen much void main in c++ unlike in java so I'll go with it, thanks 👍
23rd Jun 2018, 4:08 PM
Praful M
Praful M - avatar