Fahad Uddin Fahad Uddin - 1 year ago 94
C Question

Why don't we use (void) in main?

People use

void main() /*empty braces()*/

I have been taught to write
void main(void)

Any ideas what the difference is?

Answer Source

I'm not sure what the standards are nowadays, but in traditional ANSI C, using empty braces idicates that the function can take any number of arguments. Declaring a void parameter on the other hand indicates that the function only takes zero arguemnts. In this case (and many others), it really doesn't matter too much.

If you want to be strict though, it's probably best to define the void parameter. Of course, the main function can also be defined as int main(int argc, const char* argv[]) - which is perfectly valid, but often unnecessary if you don't care about arguments.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download