3 ms·
My favorite uses a divide by zero to terminate an otherwise infinite recursion.
by jws 16y ago
My favorite uses a divide by zero to terminate an otherwise infinite recursion.
- deleted 16y ago[deleted]
- juiceandjuice 16y agoActually the one that uses function pointers is by far the best, simplest way, and it doesn't segfault. Since x/1000 will always be floor(x/1000), once it reaches 1000 it calls nothing and exits cleanly. This one (not mine): #include <stdio.h> void nothing(int); void next(int); void (*dispatch[2])(int) = {next, nothing}; void nothing(int x) { } void next(int x) { printf("%i\n", x); dispatch[x/1000](x+1); } int main() { next(1); return 0; }