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

How To Exit A C Program In Power Shell

How To Exit A C Program In Power Shell

C is one of the most powerful programming languages and C program code can be edited and run by C or C++ IDEs and compilers. Using a fast and reliable C or C++ compiler and IDE 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.

You can run C and C++ codes in C++ compilers and build tools like C++ Builder. C++ Builder has a free C++ Builder Community Edition and C++ Builder Professional / Architect / Enterprise Versions. In this article we find out how we exit a C program in Power Shell? Is return 0; enough to exit successfully from your app? Let’s see with some short examples.

How to exit a C Program in Power Shell when running?

  • If you have running C or C++ application in Command Prompt, 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 C or C++ app on IDE, In all IDE, there is a STOP button to stop the application from running. You can use the PAUSE button to Pause and continue 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 exit a C Program in Power Shell?

In C and C++ programs we use return to exit a program in C. If you are a beginner, then “Hello World” examples are good to understand features of the programming language. It is good to understand how to edit text, how to write in its format, how to compile and link, how to debug and execute, how to deploy or release. This full example below 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 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 run and exit.

How to exit a C program without returning a value to the operating system?

In most C languages you do not need to define 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 mid or end of your main program to exit from C program. For example,

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

We highly recommend you exit by using return function. In some compilers, If you want to exit from app you can use exit(); or abort(); functions, you need to add stdlib.h header. If you want to show the exit value in terms of coding, there are two definitions, EXIT_SUCCESS and EXIT_FAILURE are defined in stdlib.h. Include stdlib.h then;

You can exit from your app as below,
return EXIT_SUCCESS;
If this is about failure of your program then you can exit from your app as below,
return EXIT_FAILURE;

How to exit a C 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 Rapid Application Development Studio, also known as RAD Studio, and C++ Builder is one of the most professional IDE’s that work under RAD Studio. It is the oldest IDE (it began as Borland TurboC in 1990 and was later renamed Borland C++ Builder). Under the Embarcadero brand, multiple new versions have been released, year upon year, along with great new features, updates, and support to ensure that your apps can stay current. RAD Studio’s C++ Builder version comes with 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 C Program In Power Shell. An example C program in the C++ Builder IDE
RAD Studio / C++ Builder 11.1

You can simply run your application in Debug mode and use the 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

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Introduction to C++Learn C++

What is A Void Function In The C Programming language?

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

How To Run A Program Written In The C Language

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

How To Compile And Run A C Program

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

How To End A C Program In An "If" Statement