c - C中是否有任何函数可以将数组的内存地址存储到变量中?什么类型的变量会存储这个地址?
问题描述
我使用下面的代码来做同样的事情。这是做同样事情的正确方法吗?
int ar[512];
char hex[100]="0xf";
sscanf(hex,"%x",ar);
printf("\n%s",hex);
基本上我需要将此十六进制值存储到一个变量中,以便我可以将此十六进制值更改为位数组。
解决方案
我相信您可以创建一个指向数组开头的指针并打印指针的地址
#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;
}
推荐阅读
- android - 如何使用firebase auth android无法返回android
- excel - 子类别的总和值
- javascript - React Native App 仅在发布版本 android 7.0 时崩溃
- android - 如何垂直和水平对齐代码?
- java - android的DownloadManager在下载失败后不恢复下载
- reactjs - 我的 React 应用程序使用时间越长越慢
- javascript - W3C、ECMAScript 或专业建议在 JavaScript 中向现有 HTML 类添加属性?
- angular - typeof @angular/http/http 类型不存在属性 ɵg
- python - 使用 spacy 解析树提取键值对
- python - 动态 dags 中的 on_failure_callback