What is the easiest way to make a C++ program crash?
The abort()
function is probably your best bet. It's part of the C standard library, and is defined as "causing abnormal program termination" (e.g, a fatal error or crash).
A C program to crash the system
It's easy to write a program that invokes undefined or implementation-defined behavior. Some of those programs could potentially crash the system.
But by definition, this is inconsistent. And modern OSes take pains (though not 100% successfully) to prevent a rogue app from crashing the system.
Why does my C program crash?
This condition makes sure that you have exactly 2 arguments or the program exists
if (argc < 2 || argc > 2)
kill("ERROR: Use: calc ");
However the next line is accessing the third argument
char operation_type = argv[2][0];
Which does not exist. And the program is killed
What is the easiest way to make a C++ program crash?
The abort()
function is probably your best bet. It's part of the C standard library, and is defined as "causing abnormal program termination" (e.g, a fatal error or crash).
Related Topics
Can Class Template Constructors Have a Redundant Template Parameter List in C++20
How to Use Windbg to Analyze the Crash Dump for Vc++ Application
Std::Shared_Ptr Initialization: Make_Shared<Foo>() VS Shared_Ptr<T>(New Foo)
Easy Way Find Uninitialized Member Variables
How Can Std::Make_Heap Be Implemented While Making at Most 3N Comparisons
Making a Template Parameter a Friend
Handling Partial Return from Recv() Tcp in C
Qt/C++ - Accessing Mainwindow UI from a Different Class
Converting Epoch Time to "Real" Date/Time
How Bad Is Redefining/Shadowing a Local Variable
How to Output the Value of an Enum Class in C++11
Has Anyone Ever Had a Use for the _Counter_ Pre-Processor MACro
Accessing Protected Members of Superclass in C++ with Templates
Why Does This Program Crash: Passing of Std::String Between Dlls