保存数组地址的指针地址如何相同? [英] How the address of pointer that holds the address of array are same?

查看:79
本文介绍了保存数组地址的指针地址如何相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里 p 是一个整数指针,可以保存 int 变量的地址,但它也有一个内存地址-存储它的位置。

Here p is a integer pointer that can hold the address of int variable, but it also has a memory address - where it is stored.


数组 a = 1002 $ b $的基地址指针的b地址 p = 2008

let base address of array a = 1002 address of pointer p = 2008

当我们写时: int * p = a ; // p指向数组a的基地址

int ** r =& p; //表示* r指向p

* r 点的地址指向 a 的地址,它应该指向 p 的地址。

how *r points to the address of a, it should point to address of p.

#include <stdio.h>
void main()
{
    int a[3] = {1, 2, 3};
    int *p =a;
    int **r = &p;
    printf("%p %p", *r, a);
}


推荐答案

请注意

int *p=a;

表示 a p 现在指向相同的地址。

means that a and p are now pointing to same address.

此外,它是 r 指向 p (是 p 的地址),而不是 * r

Also, it is r that points to p (is the address of p) and not *r.

因此要打印 p 的地址,只需使用 r 而不是 printf()中的 * r

Thus to print the address of p simply use r instead of *r in printf().

printf("%p %p", r, a);

这篇关于保存数组地址的指针地址如何相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆