一、指针
定义:指针就是地址,一串16进制的编码

int *p;
int a=10;
p=&a;
*pa=20;
a=20;
int i,b=30,a[]={3,4,5,6,7,3,7,4,4,6};
int *p=a;
*(a+i)等价于a[i]等价于p[i]等价于*(p+i);
注释:在下面字符串部分
int * const pa=a;
const int * pi与int const * pi一样;
int * const pi与int * const pi同理;
const int * const pi=&b;
void find2(char [] array, char search, char ** ppa);
void (*FunP)(int);
FunP=&MyFun;
FunP=MyFun;
(*FunP)(20);
FunP(20);
typedef void (*FunType)(int );
typedef void (*FunType)(int );
void CallMyFun(FunType fp,int x);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
二、数组
注释:
(1)数组名代表数组的首地址,a=&a[0];
(2)int a[100],在内存中占用100×4=400字节空间;
(3)a=&a[0]=&a.三者仅在数值上是相等的
(4)数组方括号中不可用变量来表示元素的个数,但是可以是符号常数或常量表达式。如:int n=5;int a[n];错误
(5)static表示是静态存储类型, C语言规定只有静态存储数组和外部存储数组才可作初始化赋值。 如: static int a[10]={ 0,1,2,3,4,5,6,7,8,9 };
(6)当{ }中值的个数少于元素个数时,只给前面部分元素赋值。而后面的元素自动赋0值
int a[10]; 说明整型数组a,有10个元素。
float b[10]; 说明实型数组b,有10个元素。
char ch[20]; 说明字符数组ch,有20个元素。
static int d[]={1,2,3,4,5};
int s[][5]={1,2,3,4,5};
char c[10];
char *p=c;
*(p+n)==c[n];
p[i]=*(p+i)=a[i]=*(a+i);
&p[i]=(p+i)=(a+i)=&a[0]+i;
static char c[]="BASIC/ndBASE";
三、字符串
注释:C语言没有单独的字符串类型,可通过数组和指针存放
char c[]="BASIC/ndBASE";
char a[10];
gets(a);
char *array;
scanf("%s",array);
char *pointer="123456";
printf("%s",pointer);
四、结构体
struct student
{
int age;
float score;
char sex;
}typeVarList;
struct student stu1,stu2;
typeVarList;
struct{}type;
struct student a={ 20,79,'f'};
struct stu{...}typeVar={ 20,79,'f'};
stu1.age=12;
printf("年龄:%d \n", a.age);
struct student stu1;
struct student *p;
p=&stu1;
(*p).age;
p->sex='男';
struct student stu[3]={{ 20,79,'f'},{ 20,79,'f'},{ 20,79,'f'}};
(1)stu1.name
(2)(*p).age;
(3)p->sex='男';