i've seen both, but only used void main() and getch(); as that has been all my high school has ever taught me. Is there any difference in the two? (i'm using borland 5.02 btw)....
i've seen both, but only used void main() and getch(); as that has been all my high school has ever taught me. Is there any difference in the two? (i'm using borland 5.02 btw)....
if you know about functions, you will know that main is just another function... so:
void main(void) - is a function that returns nothing and takes in nothing.
int main(void) - is a function that returns an int and takes in nothing.
int main(char*,int) - is a function that returns an int and takes in a pointer to a char and an int
getch() - is only borland specific.
all it does is wait for a user to press <enter>
return 0 just exists the program if u start the program with an int return type...
You should use main in this form
Code:main( int argc, char *argv[ ], char *envp[ ] )
{
program-statements
}
getch() is not borland specific... Its available where ever it is defined...Quote:
getch() - is only borland specific.
You can use it in VC++ by including conio.h or on pretty much any UNIX machine by including... curses.h or ncurses.h
Actually it retrieves a character from standard input (STDIN) without echo'ing it... although waiting for user to press enter is one use of it.Quote:
all it does is wait for a user to press <enter>
Use return 0 if it is at all possible. Sometimes the program will quit if you just return 0, so getchar() (the stdio version of getch()) is required. If it was me, I would probably hurt anyone who put that at the end of a program.
Z.
char* envp[] as argument to main is microsoft specific.
and the totally ansi version of main is:
int main (int argc, char* argv[]);
it doesnt matter what the variable name is.Quote:
Originally posted by CornedBee
char* envp[] as argument to main is microsoft specific.
and the totally ansi version of main is:
int main (int argc, char* argv[]);
Actually...there's a very good reason why you should not use void main(...).
On Intel/Win32, return values from functions are normally passed through EAX (the register). So therefore, if you don't return a value it's not really a problem.
However, some systems return values on the stack, so if you haven't pushed a value, then it'll all be out of sync and gets very messy indeed.
Moral of the story, do what ANSI and ISO tell you to do :)
the variable name does not matter, but no system/compiler combo except win32/vc++ will fill anything into the third argument
aah I see. thx