@pnck
2015-11-15T23:38:40.000000Z
字数 3710
阅读 2112
presentation
typedef struct _NODE
{
struct _NODE* next;
}NODE;
struct DATA1_WITH_LIST
{
NODE list_node;
//any_data
int data;
char str[600];
}
struct DATA2_WITH_LIST
{
NODE list_node;
//any_data
int data;
struct StuInfo stu;
}
N0DE n1,n2,n3,n4;
n1.next = n2;
n2.next = n3;
n3.next = n4;
n4.next = n1;
n2.next = n4;//剔除n3
NODE * n7 = malloc(sizeof(NODE));
n7->next = n4;
n2.next = n7;
free(n7);
n2.next = n4;//n7被踢
InitList()
{
NODE *n1 = malloc(sizeof(NODE));
}
AddNode(NODE * 某一node)
{
NODE *new_node = malloc(sizeof(NODE));
new_node->next = 某一node->next;
某一node->next = new_node;
}
DelNode(NODE * 某一node)
{
}
AddNode(struct NODE* nd)
{
NODE *newNode (struct NODE*) = malloc(sizeof(struct NODE));
newNode->pNext = nd->pNext;
newNode->pPrev = nd;
nd->pNext = newNode;
newNode->pNext->pPrev = newNode;
}
void func(int a)
{
puts("this is a function");
}
void func3(int a)
{...}
int func2(char a, char b)
{...}
int main()
{
int func2(char, char); //声明
func();
TYPE * var_name;//定义TYPE类型的指针
void (*pFunc)(int a);
pFunc = func;//将函数地址赋值给函数指针
pFunc(10);//调用func
pFunc = func3;
pFunc(10);//调用func3
int (*pFunc2)(char, char);
pFunc2 = func2;
pFunc2('a', 'b');
}
#define pi 3.14
#define TRUE 0
typedef int DOULBE;//NOOOOOOOO
sizeof
double CalcArea(double r)
{
return r * r * pi;
}
struct StuInfo
{
char name[60];
double mark;
};
typedef struct StuInfo
{
char name[60];
double mark;
} STUINFO, *STUINFO_PTR;
struct StuInfo -----> > STUINFO
struct StuInfo* -----> STUINFO_PTR
//leagacy define
struct StuInfo stu1;//变量
struct Stuinfo* stu2;//指针
//new way
STUINFO stu1;
stu1.name
stu1.mark
STUINFO_PTR stu2;
stu2->name//.换成了->
stu2->mark
strcpy(stu.name, "maodada");
stu.mark = 101;
char array[10];
sizeof(array);
void GetArray(char a[]/*char *a */)
{
sizeof(a);//Never
}
void swap(int a, int b) {..}
...
int aa = 1, bb = 2;
swap(aa, bb);
//...any output
void* malloc(/*size*/)
void free(/*ptr*/)
char *a = malloc(10);//生成了10个元素的char数组
//papapa
//...
//完了
free(a);
memory - allocation
scanf("%d %d %d", &x, &y, &z);
double mat[x][y];//you want this
double *dynamic_mat = malloc(x*y*z*sizeof(double));
//double normal[x*y*z];//=L=
//normal[0][0]
//dynamic_mat[0][1]//can this
//dynamic_mat[0][1][2]//wrong
//double *mat = malloc(10*sizeof(double));
//数组名 是 一个指向第一个元素的指针
//一个指向第一个元素的指针 是 数组名
mat:
[00][01][02][03]
[10][11][12][13]
[20][21][22][23]
...
mat ---> double*
mat[1] ---> double*[1] ---> double
mat[0][1]---> double [1] ---> ?
//没有办法变成二维的数组!!
//mat 如果是多一级的指针呢?
mat ---> double**
mat[1] ---> double**[1] ---> double*
mat[0][1]---> double* [1] ---> double
//三维?
mat ---> double***
mat[1] ---> double***[1] ---> double**
mat[0][1]---> double** [1] ---> double*
mat[0][0][0]-> double* [0] ---> double
mat ---> double** -- > double* (*x2)
mat[0] ---> double*(*x1)
mat[0][0]---> double*
mat[0][0][0]-> double*[0] ---> double
///指针最高只需要2级,够了。
double * MatPlus(double *m1, double *m2)
{
//...
}
mat[0]
mat[1]
list[0]
list[1]
int **mat = malloc(x*sizeof(int*));
for (int i = 0; i < x; i++)
{
mat[i] = malloc(y * sizeof(int*));
for (int j = 0; j < y; j++)
{
mat[i][j] = malloc(z * sizeof(int))
}
}
for(;i<sizeof_pic;i++)
{
brighten(points[i]);
}
for(;i<sizeof_pic;i++)
{
darken(points[i]);
}
for(;i<array_size;i++)
{
plusOne(array[i]);
}
void (*func)(int);
func = brighten;
//func = darken;
//func = PlusOne;
for(;i<sizeof_pic;i++)
{
func(points[i]);
}
void brighten(int *pt_value)
{
*pt_value = *pt_value*2;
}
void ProcEveryPoint(void (*func)(int *pt_value),int *Points,int n)
{
for(int i=0; i<n; i++)
{
func(&Points[i]);
}
}
void my_proc(int *pt_value)
{
//i can do anything
}
ProcEveryPoint(my_proc,Points,n);//这里永远是固定的
ProcEveryPoint(darken,Points,n);
ProcEveryPoint(brighten,Points,n);
ProcEveryPoint(plusOne,Points,n);
void swap(int *a,int *b)
{
int t = *a;
*a = *b;
*b = t;
}
int x,y;
swap(&x,&y);
int *px = &x;
int *py = &y;
swap(px,py);
//指向关系没有改变
px --> x
py --> y
/////若要
px --> y
py --> x
swap(&px,&py);
px --> y
py --> x
void swap(int **a, int **b)
{
int *t = *a;
*a = *b;
*b = t;
}