+ 1
Difference between return and getch()
I saw some programmer use getch() statement instead of return statement while ending the C++ or C program What are the difference between the two? Why some use the getch() and others use return? Which is effective and why?
2 Respuestas
+ 2
`getch()` reads user input. I have seen people use `getch()` so the user has to press a key before the program exits, so the console window doesn't close immediately, which is probably what you mean.
`return` is not a function (so it's just `return`, not `return()`). If you don't return from your main function, a `return 0;` is inserted automatically for you. You will see `return` a lot once you learn about writing your own functions.
So: Your program always returns when ending, and the `getch()` function doesn't really have anything to with ending a program. They are two completely seperate things!
0
Schindlabua Thank for the answer. Ik that return is not a function. But I typed it wrongly as if it's a function.