c基礎很薄弱,僅限非計算機專業大學學的那點點基礎。以後會每天更新個人的學習筆記。菜鳥的我是這樣學下來滴。走過路過的,不許笑話。有緣看見的,歡迎指點。
函數名本身作爲指針,指向函數代碼首地址
函數體放在代碼區
1.返回值爲指針的函數成爲指針函數
2.函數指針:指向函數的指針
函數聲明類型一致,函數指針類型一致
void fun (char *b ); 函數指針爲 void (*ptr)(char *);
賦值形式 ptr=fun;
3.調用函數:兩種形式相同
fun();
ptr();
4.函數指針的應用
函數名不可以改變指向,指針可以改變指向
用函數指針調用函數必須寫成函數形式
5.函數指針數組
int add(int ,int);
int sub(int ,int);
int mul(int ,int);
int (*ptr[])(int ,int)={add,sub,mul}; //此爲函數指針數組
6.指針的傳址調用
函數多個返回值--通過參數列表
int A(int *a,char *c,int x,double b)
7.遞歸函數
函數自己調用自己
遞歸函數在棧區,耗內存大
[棧區特點:先進後出,後進先出]
遞歸函數運行時,在棧區開闢一塊內存,運行中所有結果包存在棧區,輸出所有結果完成,釋放所有內存
數據結構中 樹 用遞歸函數比較多
構造類型
1.定義類型
struct student
{
int num;
char name[34];
int grade;
};
[相當於 int 可以用來定義變量]
2.定義變量
struct student stu1;
3.初始化
struct student stu1={1,"chains",34}
4.賦值
方法一stu1.num=1; strcpy(stu1.name,"abc"); [字符串不可以直接賦值,必須用字符串拷貝函數處理]
方法二stu3=stu2
5.結構體與指針的關係
struct student *p;
p=&stu1;
6.用指針取結構體內參數
方法一 (*p).num;(*p).name;
方法二 p->num; (常用)
7.在堆區創建結構體內存
struct student *ptr=malloc(sizeof(struct student)); //容易出錯的地方,總是弄混數據類型 [!!!struct XXXX]
8.結構數組
struct student stu[3]={stu[0],stu[1],stu[2]};
stu=&stu[0];stu+1=&stu[1];
stu[1].name == (stu+1)->name
9.初始化
struct student stu[2]={{1,"name",45},{3,"chafde",64}}