C/C++ black screen opens and closes

While executing a program in C++, it happens the black screen opens and closes automatically without displaying the output(program is correct). How to recover from this situation?

Showing Answers 1 - 6 of 6 Answers


  • Sep 26th, 2011

Yeah .. Surendra is right..

This happens when getch() or getche() is not given at the end.

getch will let the output to be displayed till the user enters a character.
As soon as the user enters a character it transfers the control back to the main function.
Then it continues executing the rest of the lines.

  Was this answer useful?  Yes


  • Oct 4th, 2011


  Was this answer useful?  Yes


  • Aug 25th, 2013

Try this

  1. system("pause");

  Was this answer useful?  Yes


  • Jun 27th, 2014

use getchar() before return in the main.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions