c/c++ 在 main 函數之前和之後發生的那些事。
#include <stdio.h> #include <stdlib.h> #include <iostream> void foo() { printf("call back atexit, C can do it after main.\n"); } int bar() { printf("global variable initialized, C can do it before main.\n"); atexit(foo); return 0; } int x = bar(); class CTest { public : CTest() {printf("constructor, C++ can do it before main.\n");} ~CTest() {printf("destructor, C++ can do it after main.\n");} }; CTest ct; int main(void) { printf("hello world!\n"); return 0; }