首页 > 解决方案 > C中是否有任何函数可以将数组的内存地址存储到变量中?什么类型的变量会存储这个地址?

问题描述

我使用下面的代码来做同样的事情。这是做同样事情的正确方法吗?

int ar[512];
char hex[100]="0xf";
sscanf(hex,"%x",ar);
printf("\n%s",hex);

基本上我需要将此十六进制值存储到一个变量中,以便我可以将此十六进制值更改为位数组。

标签: c

解决方案


我相信您可以创建一个指向数组开头的指针并打印指针的地址

#include <stdio.h>
int main(void)
{
    // my array
    int a[2];
    //my pointer pointing to the start of my array
    int *mysillypointer = &a;
    //print the addres of my pointer
    //the pointer is the "variable " that has the address of your array
    printf("Address of array a is : %p\n",mysillypointer);


    return 0;
}

推荐阅读