1、文件组合
1、关于函数
myfun.c
#include "myfun.h"
myfun.h
int myfun(int a, int b);
2、关于主程序
main.c
#include "myfun.h"
2、编译 gcc myfun.c main.c -o main
3、数组作为函数参数
在函数内部无法通过这个指针获得数组长度,必须将数组长度作为函数参数传递到函数内部,于是就有了第二个参数 n。
void func(int p[], int n)
3、获取数组长的办法
(1)
int a[10] = {0};
int cnt = sizeof(a) / sizeof(a[0]);
(2)利用库函数
strlen;
(3)返回数组指针
函数int *a(void)中定义的数组 a[4];属于局部变量,在子函数结束时会被释放,所以返回的指针变成野指针,会乱码;简单的解决方法有两种,1. 将数组定义在主函数之前(#include
其中malloc的用法
int *p; p=(int *)malloc (100*sizeof(int));
(4)防止头文件重复包含
#ifndef __SOMEFILE_H__ #define __SOMEFILE_H__ ... ... //一些声明语句 #endif



