Minimal C/C++ program that segfaults? [duplicate]

main() { *(int *)0xdeadbeef = 37; } should do it.


main;

Is portable, and segfault in 5chars.
It's a variable declaration - int type is implied (feature copied from B language) and 0 is default value. When executed this tries to execute a number (numbers aren't executable), and causes SIGSEGV.

Source: https://codegolf.stackexchange.com/questions/4399/shortest-code-that-raises-a-sigsegv


try this:

long* ptr = 0x0; //-- you can also use other random values and likely you will segfault
printf("%f", *ptr);