C语言教程:指向另一个指针地址的指针

2018-10-0708:05:04编程语言入门到精通Comments7,845 views字数 711阅读模式

C语言中指针的指针概念中,指针指向另一个指针的地址。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

C语言中,指针可以指向另一个指针的地址。我们通过下面给出的图来理解它:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

C语言教程:指向另一个指针地址的指针文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

我们来看看指向指针的指针的语法 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

int **p2;
C

指针的指针的示例

下面来看看一个例子,演示如何将一个指针指向另一个指针的地址。参考下图所示 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

C语言教程:指向另一个指针地址的指针文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

如上图所示,p2包含p的地址(fff2)p包含数字变量的地址(fff4)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

下面创建一个源代码:pointer-to-pointer.c,其代码如下所示 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

#include <stdio.h>        
#include <conio.h>      
void main() {
    int number = 50;
    int *p;//pointer to int  
    int **p2;//pointer to pointer      

    p = &number;//stores the address of number variable    
    p2 = &p;

    printf("Address of number variable is %x \n", &number);
    printf("Address of p variable is %x \n", p);
    printf("Value of *p variable is %d \n", *p);
    printf("Address of p2 variable is %x \n", p2);
    printf("Value of **p2 variable is %d \n", **p2);

}
C

执行上面示例代码,得到以下结果 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html

Address of number variable is 3ff990
Address of p variable is 3ff990
Value of *p variable is 50
Address of p2 variable is 3ff984
Value of **p2 variable is 50
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/6434.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/ymba/6434.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定