📜  数据结构指针

📅  最后修改于: 2020-10-14 06:48:00             🧑  作者: Mango

指针

指针用于指向存储在计算机内存中任何位置的值的地址。要获取存储在该位置的值,称为取消引用指针。指针可提高重复过程的性能,例如:

  • 遍历字符串
  • 查找表
  • 控制表
  • 树状结构

指针详细信息

  • 指针算术:指针中可以使用四种算术运算运算符:++,-,+,-
  • 指针数组:您可以定义数组以容纳多个指针。
  • 指向指针的指针: C允许您将指针放在指针上,依此类推。
  • 传递函数指针在C:通过引用或地址使能传递的参数将参数传递给在调用函数被调用的函数而改变。
  • C中的函数返回指针 C允许函数返回指向局部变量,静态变量和动态分配的内存的指针。

程序

指针

#include 

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                                                                                                                 
address of a = 3010494292                                                                                                      
address of a = -1284473004                                                                                                     
address of b = 3010494296                                                                                                      
value of b = address of a = 3010494292

程序

指针到指针

#include 

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 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