数组在函数内部会退化成指针,普通数组就是指针,指针数组退化成二级指针
指向数组的指针
#include<stdio.h>
void main(int argc,char *argv[]) {
int a[5] = { 1,2,3,4,5 };
int *p;
p = a;
for (int i = 0; i <= 5; i++) {
printf("%d,%x\n", *(p + i), p + i);
}
printf("%d", argc);
getchar();
}
结构体
#include<stdio.h>
struct info {
char name[22];
int id;
};
void main() {
struct info a;
strcpy( a.name, "sss");
a.id = 3;
printf("%s,%d\n",a.name, a.id);
struct info *p;
p = &a;
printf("%s,%d\n", p->name, p->id);
printf("%s,%d\n", (*p).name, (*p).id);
getchar();
}
C语言有一bai种数据类型叫结构体,其定义格式du为:
struct 结构体zhi名 {
结构体成员变量dao定义;
};
如:
struct student {
char name[20];
int age ;
double score ;
};
用结构体定义的变量叫结构体变量,如:
struct student stu; //定义一个结构体变量stu
这种变量在引用结构体成员时,使用点(.)来操作,如:
strcpy( stu.name, "zhangsan" );
stu.age=20;
stu.score=100;
结构体类型也可以定义指针变量,如:
struct student *pstu; //定义一个结构体指针变量pstu
pstu=&stu ; //pstu指针指向stu结构体变量
结构体指针变量在引用成员变量时,使用箭头(->)来操作,如:
strcpy( pstu->name, "zhangsan" );
pstu->age=20;
pstu->score=100;
以上这两种符号的使用是C语言的规定!
(*a).b 等价于 a->b。