×
数据结构教程数据结构简介数据结构算法数据结构渐近分析指针结构体

数组

数组二维数组

链表

链表双链表循环单向链表循环双向链表

堆栈

堆栈数组实现堆栈堆栈的链表实现

队列

队列队列的数组实现队列的链表实现循环队列

二叉树二叉搜索树平衡搜索树(AVL树)B树B+树

图类型图的表示广度优先搜索(BFS)算法深度优先搜索(DFS)算法生成树

搜索

线性搜索二进制(二分查找)搜索

排序

冒泡排序桶排序梳排序计数排序堆排序插入排序合并排序快速排序基数(Radix)排序选择排序希尔排序双调排序鸡尾酒排序圈排序

指针


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

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

指针详细信息

  • 指针算术:指针中有四个算术运算符:++--+-
  • 指针数组:可以定义数组以容纳多个指针。
  • 指针的指针:C语言允许指针的指针等等。
  • 将指针传递给C语言的函数:通过引用或地址传递参数使得被调用函数可以在调用函数中更改传递的参数。
  • 从C语言函数返回指针:允许函数返回指向局部变量,静态变量和动态分配内存的指针。

指针示例程序

#include <stdio.h>  

int main()
{
    int a = 5;
    int *b;
    b = &a;

    printf("value of a = %dn", a);
    printf("value of a = %dn", *(&a));
    printf("value of a = %dn", *b);
    printf("address of a = %un", &a);
    printf("address of a = %dn", b);
    printf("address of b = %un", &b);
    printf("value of b = address of a = %u", b);
    system("pause");
    return 0;
}

执行上面示例代码,得到以下结果 -

value of a = 5
value of a = 5
value of a = 5
address of a = 13630708
address of a = 13630708
address of b = 13630696
value of b = address of a = 13630708

指针的指针示例程序

#include <stdio.h>  

int main()
{
    int a = 5;
    int *b;
    int **c;
    b = &a;
    c = &b;
    printf("value of a = %dn", a);
    printf("value of a = %dn", *(&a));
    printf("value of a = %dn", *b);
    printf("value of a = %dn", **c);
    printf("value of b = address of a = %un", b);
    printf("value of c = address of b = %un", c);
    printf("address of a = %un", &a);
    printf("address of a = %un", b);
    printf("address of a = %un", *c);
    printf("address of b = %un", &b);
    printf("address of b = %un", c);
    printf("address of c = %un", &c);
    system("pause");
    return 0;
}

执行上面示例代码,得到以下结果 -

value of a = 5
value of a = 5
value of a = 5
value of a = 5
value of b = address of a = 16252636
value of c = address of b = 16252624
address of a = 16252636
address of a = 16252636
address of a = 16252636
address of b = 16252624
address of b = 16252624
address of c = 16252612

分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)