+ 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?

20th Dec 2018, 3:11 PM
Aadhish Sriram
Aadhish Sriram - avatar
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!
20th Dec 2018, 5:42 PM
Schindlabua
Schindlabua - avatar
0
Schindlabua Thank for the answer. Ik that return is not a function. But I typed it wrongly as if it's a function.
21st Dec 2018, 2:19 AM
Aadhish Sriram
Aadhish Sriram - avatar