This is the answer for one of the simple function question from my programming lab...

#include <iostream>
using namespace std;

void displayHi();

int main(void)
{
    displayHi();
}

void displayHi()
{

cout<<"I love c++";

}

but what i dont understand is why we should put main(void)??
why dont simply type main()??

and by the way,what does it means by put main(void)??
because what i know inside the parenthess if we want to declare variable,it should maybe like this one : main(void variable)...
is that correct, we just put the type,but not declare any variable just like this one : main(void)??

Thank You....

You dont need to put main(void). This isnt good programming if you do that. void main() just means that the programming doesnt return any value. If you use int main(), there has to be a return value. I'm no expert but i have never used int main(void). If the main program doesnt need to have a value passed in, you dont need a value inside the parenthesis. Hope this helps

void main() just means that the programming doesnt return any value.

Never ever recommend void main() because it isn't recognized by either C or C++ standards. Read this article.

That is Microsoft and they do whatever they want. Microsoft does NOT control the C/C++ standrds committee. Other compilers will (or may) produce errors because void main() is non-standard.

erm people...i'm sorry..
but i'm not asking about the void main();

what i actually asked is what does int main(void); means...

and plus,i ever seen the other function that being written with void in the parenthesis..for example is draw_circle(void) and so on..

could somebody explain it plz?

In c++ int main() and int main(void); are the same thing. You are free to code it either way, unless your teacher tells you otherwise.

my teacher dont say anything yet..

but is that int main(void) means that main function does not return any value??

No, the int means the function returns an integer. The void means main() does not have any parameters.

There are three ways to code main(). Any other way is non-standard and may or may not be supported by your compiler. int main() int main(void) int main(int argc, char* argv[])

oh..if like that...
is that ok if i also write any other function like this :
void myfunction(void)??

yes, that's ok too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.