Code:
#include <stdio.h>
void main ( void )
{
printf("Hello World!\n");
return;
}
Code:
#include <stdio.h>
int main ( void )
{
printf("Hello World!\n");
return 0;
}
Don't use void main!
Code:
#include <stdio.h>
int ReturnsSomething ( void );
void DoesntReturnSomething ( void );
int main ( void )
{
printf("Checking return status of functions..\n");
printf("Press any key..\n\n");
getchar();
if ( ReturnsSomething() == 0 )
{
printf("He was nice.\n");
}
else
{
printf("He wasn't so nice!\n");
}
if ( DoesntReturnSomething() == 0 )
{
printf("He was nice.\n");
}
else
{
printf("He wasn't so nice.\n");
}
return 0;
}
int ReturnsSomething ( void )
{
return 0;
}
void DoesntReturnSomething ( void )
{
return;
}
Void main doesn't return a status. How can your operating system check the return status of a program that doesn't return a status? Your operating system expects you to return something, if you don't it gets confused, and it's also undefined behavior - that's not good.
Search the board using the search function to read more on this.
- edit -
Heh, I'm not sure if that compare program will compile or not... ah well, search for void main ...and you got your 2 examples.
Good luck.