基本知识
- 指针是一种特殊的变量,存放的是另一个变量的地址
- 指针的类型是其所指向的变量的类型
- 指针指向的是数组元素时,才进行算数运算或大小比较
联系
指针与数组
int a[6] = {0, 1, 2, 30, 40, 50};
int* p = &a[0];
printf("%d %d\n", p[2], *(p + 2));
printf("%d\n", *p++);
printf("%d\n", *p);
printf("%d\n", *++p);
printf("%d\n", *p);
printf("%d\n", (*p)++);
printf("%d\n", *p);
printf("%d\n", ++(*p));
printf("%d\n", *p);
指针与结构
typedef struct time{
int year;
int month;
int day;
}data;
int main()
{
data tomorrow = {2017, 9, 22}, today;
data* oneDay;
oneDay = &today;
today.year = 2017;
(*oneDay).month = 9;
oneDay->day = 21;
printf("%04d %02d %02d", today.year, today.month, today.day);
return 0;
}