1、數據類型函數
【例子】指針
//no.1 int a,b,c; a = 1; b = 2; c = a + b; //no.2 char s; s = ‘a’; float f; f = 3.1415;
【例子】code
struct Student{ int num; char name[20]; int age; float score; }; struct Student s1,s2; s1.num = 101; s2.num = 102;
typedef int Integer; typedef float Real; int i,j; ——>Integer i,j; float a,b; ——>Real a,b;
typedef struct Student{ int num; char name[20]; int age; float score; }Student; Student s1,s2; s1.num = 101; s2.num = 102;
【例子】內存
//no.1 int *a; int b = 0; a = &b; *a = 1; ——>b = 1; //no.2 char *c; char d = ‘a’; c = &d; *c = ‘A’; ——>d = ‘A’; //no.3 typedef struct Student{ int num; char name[20]; int age; float score; }Student; Student s1; Student *s1_p; s1_p = &s1; s1.age = 23; ——> (*s1_p).age = 23; ——> s1_p->age = 23;
2、函數原型
//no.1 void fun(int num){ num++; } int a = 1; fun(a); printf(「%d」,a); //no.2 void fun(int &num){ num++; } int a = 1; fun(a); printf(「%d」,a); //no.3 void fun(int a[]){ a[0]++; } int a[10]; a[0] = 1; fun(a); printf(「%d」,a[0]);
3、動態內存分配變量
float *f = (float *)malloc(4); char *c = (char *)malloc(1); Student *s1_p = (Student *)malloc( ??);
int num1 = sizeof(float); int num2 = sizeof(char); int num3 = sizeof(Student); float *f = (float *)malloc(sizeof(float)); char *c = (char *)malloc(sizeof(char)); Student *s1_p = (Student *)malloc(sizeof(Student));
float *f = (float *)malloc(sizeof(float)); char *c = (char *)malloc(sizeof(char)); Student *s1_p = (Student *)malloc(sizeof(Student));、 ……//此處省略部分操做 free(f); free(c); free(s1_p);