What is the easiest way to make a C++ program crash?
Solution 1:
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).
Solution 2:
Try:
raise(SIGSEGV); // simulates a standard crash when access invalid memory
// ie anything that can go wrong with pointers.
Found in:
#include <signal.h>
Solution 3:
Dividing by zero will crash the application:
int main()
{
return 1 / 0;
}
Solution 4:
*((unsigned int*)0) = 0xDEAD;
Solution 5:
Well, are we on stackoverflow, or not?
for (long long int i = 0; ++i; (&i)[i] = i);
(Not guaranteed to crash by any standards, but neither are any of the suggested answers including the accepted one since SIGABRT
could have been caught anyway. In practice, this will crash everywhere.)