函數名做函數參數
記下來備忘,基礎牢固一些,會減少一些不必要的錯誤
1 //定義比較函數max(int,int)
2 int max(int a,int b)
3 {
4 return a>b?a:b;
5 }
6 //指針fun作為compare函數的形式參數1,表明compare函數的形參1為
7 // 有2個 int型 參數的 函數指針(或稱之為函數地址/入口)
8 //注意:int (*fun)(int,int)並不需要fun指針指向函數的參數 如下調用時***
9 //compare內部調用fun指針指向的函數,此函數的參數為c,d
10 int compare(int (*fun)(int,int),int c,int d)
11 {
12 return fun(c,d);
13 }
14
15 int main(int argc, char *argv[])
16 {
17 int temp1 = 0,temp2 = 3;
18 //***
19 //調用時,實參只需填入參數為(int,int)型的函數地址(函數名即位函數地址)
20 printf("max = %2d\r\n",compare(max,temp1,temp2));
21 }
運行結果:

宏定義#undef以及多行宏定義
#undef 將已定義的宏定義撤銷;
多行宏定義 宏定義內容過長或為了閱讀便利而將一行內容拆分為多行
#ifdef MYDEFINE #undef MYDEFINE #endif #define STR1 "This is my\ //符號"\"連接本行與下一行,作用相當於字符串的重載"+" my test\ string"
主函數內容如下:
#ifdef MYDEFINE
printf("use mydefine\r\n");
#else
printf("%s\r\n",STR1);
#endif
運行結果如下:

小結
越是基礎,細節的東西,越要重視。
