指针实例理解

来源:互联网 发布:如何学软件技术培训 编辑:程序博客网 时间:2024/05/17 01:24
# include <stdio.h>

//指针与数组 
void pArry(int *p){
for(int i = 0; i < 4; i++){
printf("%d ",p[i]);
}
printf("\n");
}
//结构体 
struct Person{
char *name;
int age;
}person;

void prin(Person *p){
printf("%d %s\n",p->age,p->name);
}

int main()
{
//指针与常数
int num = 10;
int *p = &num;
printf("%d %d \n",p,*p); //p是存储10的地址 10485316 *p是存储的值10
//指针与数组
int arryto[4] = {0,1,2,3};
pArry(arryto);
int arry[4] = {1,2,3,4};
int *data[4] = {arry,arry+1,arry+2,arry+3};
printf("注意理解:%d %d %d\n",data[0], *(data[0]),*(*data));
person.age = 10;
person.name = "你好";
prin(&person);
//指针与数组需要会应用 对指针的处理(包括野指针)等等 
return 0;
}
0 0
原创粉丝点击