The smallest program in C that crashes

The smallest program in C that crashes

Sergey Abbakumov

Do you know how to write the smallest C program that will crash when it starts? Here it is:

int main;



Here's an example of the launch:

clang --std=c11 crash.c && ./a.out
crash.c:1:1: warning: variable named 'main' with external linkage has undefined behavior [-Wmain]
int main;
^
1 warning generated.
Segmentation fault (core dumped)



You might notice that exporting the main variable is undefined behavior. In older versions of the language, you could omit the int, which the compiler added by default.


Telegram channel: https://t.me/sea_plus_plus

Report Page