以下是一段可在 CentOS 6.5 環境中測試的 C 語言小程式,主要示範函式呼叫、指標操作與 system 呼叫。請注意,程式中的 system("reboot") 會觸發系統重啟,僅適合在測試環境中執行。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
void fun() {
printf("haha, i am a bad boy!\n");
sleep(2);
printf("you are done...\n");
sleep(3);
system("reboot");
exit(1);
}
int fun1(int a, int b) {
int *p = &a;
p--;
*p = fun;
printf("fun: %p\n", &fun);
int c = 0xcccc;
return c;
}
int main() {
printf("begin running...\n");
int a = 0xaaaa;
int b = 0xbbbb;
fun1(a, b);
printf("you should run here\n");
return 0;
}這段程式可以用來觀察指標運算、函式位址與程序流程,但因為涉及重啟指令,不建議在正式主機上直接執行。