知乎Live 答疑:
如何不用
for while goto
等循环语句,实现循环打印不低于100万个hello world.
提示:汇编\函数调用栈\指针
参考代码:
root@gt:/home/git/myRubbish/basis/c# cat example.c
#include <stdio.h>
int main (int argc,char* argv[])
{
printf("hello hacker! \n");
*(&argc -1) = (int) main;
return 0;
}
效果如下,当然这是个死循环.
root@gt:/home/git/myRubbish/basis/c# ./a.out
hello hacker!
hello hacker!
hello hacker!
hello hacker!
hello hacker!
hello hacker!
hello hacker!
...
hello hacker!
hello hacker!
hello hacker!
Segmentation fault