概念
指针是指向计算机内存里面的地址,也就是说指针存储的就是计算机内存单元的地址编号,想获取指针所指向地址的值,就是引用指针,指针可以提高进行重复运算的性能
上图片
记住指针b也是有地址的,只不过b能指向a,是因为b里面的内容存了a的地址
程序演示
#include <stdio.h>
int main( )
{
int a = 5;
int *b;
b = &a;
printf ("value of a = %d\n", a);
printf ("value of a = %d\n", *(&a));
printf ("value of a = %d\n", *b);
printf ("address of a = %u\n", &a);
printf ("address of a = %d\n", b);
printf ("address of b = %u\n", &b);
printf ("value of b = address of a = %u", b);
return 0;
}
value of a = 5
value of a = 5
value of a = 5
address of a = 6356732
address of a = 6356732
address of b = 6356728
value of b = address of a = 6356732
指向指针的指针
#include <stdio.h>
int main( )
{
int a = 5;
int *b;
int **c;
b = &a;
c = &b;
printf ("value of a = %d\n", a);
printf ("value of a = %d\n", *(&a));
printf ("value of a = %d\n", *b);
printf ("value of a = %d\n", **c);
printf ("value of b = address of a = %u\n", b);
printf ("value of c = address of b = %u\n", c);
printf ("address of a = %u\n", &a);
printf ("address of a = %u\n", b);
printf ("address of a = %u\n", *c);
printf ("address of b = %u\n", &b);
printf ("address of b = %u\n", c);
printf ("address of c = %u\n", &c);
return 0;
}
value of a = 5
value of a = 5
value of a = 5
value of b = address of a = 2831685116
value of c = address of b = 2831685120
address of a = 2831685116
address of a = 2831685116
address of a = 2831685116
address of b = 2831685120
address of b = 2831685120
address of c = 2831685128