CC++Introduction to C++Learn C++

How To Exit From A Program In C On Windows

C is one of the most powerful programming languages. There are a great selection of C++ windows development tools, IDE’s and C++ compilers which can also work with C programs. Using a fast and reliable C or C++ compiler for Windows is very important for beginners and professionals since it helps C/C++ developers in remembering which language features exist, how to use them, and even detect errors when we get them wrong.

Put simply, you can run C and C++ code by the C++ compilers and build tools like C++ Builder. C++ Builder has free C++ Builder Community Edition and C++ Builder Professional / Architect / Enterprise Versions. So, how we can exit from a running C or C++ app? How we can exit from a loop in a C or C++ app but not from the main program? Is return 0; enough to exit successfully from your app? Let’s see it all with a few examples.

How to exit a running C or C++ program?

  • If you have C or C++ application running in the Command Prompt or terminal, and it is in loop or you want to end this running program, just press Ctrl+C to end the app.
  • If you are running a C or C++ app in the IDE, In all IDEs, there is a STOP button to stop the application from running. You can use the PAUSE button to Pause and continue the apps too.
  • In Windows, If you are not able to end your C++ application, the last chance is to use Task Manager. Right-click to the taskbar, choose Task Manager, and In the Task Manager, find your C++ app listed in the Task Manager and right-click on it then end that task.

How to properly exit a program in C?

In C and C++ programs we use return to exit a program in C. Here’s an example below which is a “Hello World” C example that can be run with C++ Builder.

In this example above we define main() function as a integer (int) function, that means we should return a integer value. Here, we print a text with the printf() function and then we wait to get a character input (key press) with getchar(); function. Sometimes this is necessary to see results when running it. Then we exit and return 0; which means our main app successfully ran and exited with no errors.

In most C languages you do not need to define the main() program as int. That means you don’t need to return 0. For example, this program will exit automatically,

You can use return in the middle or end of your main program to exit from a C program. For example,

The example above is a void main() function. Some C compilers require the main function to be defined as void. Again, you do not need to use return; because it is a void function, as in example below,

How to exit a program in C++ Builder?

cbuider_studio_final_icons_64-9744851-4964591-6127446-4112068-5843153

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, macOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. C++ Builder comes with RAD Studio and the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

How to Exit a Program in C++ Builder. The RAD Studio Welcome Screen
The Latest RAD Studio, C++ Builder Welcome Screen

You can simply run your application in Debug mode and use STOP button to exit from your C or C++ application.

You can download the free C++ Builder Community Edition here: https://www.embarcadero.com/products/cbuilder/starter.

Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. Please visit https://www.embarcadero.com/products/cbuilder.

Download RAD Studio 11 Now

See What’s New in RAD Studio 11

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He was born in 1974, Eskisehir-Turkey, started coding in college and graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. He worked as a research assistant at the same university for more than 10 years. He received his MSc and PhD degrees from the same department at the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17Learn C++Templates

Learn How To Eliminate Pointers In Templates in C++

C++C++11C++14C++17Learn C++Templates

Learn To Export And Import Template Members From A DLL Or A Package In C++

C++C++11C++14C++17Learn C++Templates

What Is A Function Template In C++?

C++C++11C++14C++17Learn C++Templates

What Is A Class Template In C++?