c语言给动态分配的内存赋一个字符串首元素地址,为什么这块动态分配内存保存的值和这个字符串地址不同?

【新手求助~】#include<stdio.h>#include<string.h>#include<stdlib.h>intmain(intargc,charconst... 【新手求助~】
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
char buf[]="hello";
char *p=(char *)malloc(sizeof(char *));
*p=buf;
printf("buf=%p\n", buf); // buf=000000000022FE40
printf("*p=%p\n", *p); // *p=0000000000000040

return 0;
}
环境是win7 dev c++ 。
展开
 我来答
处摇胼手胝足
2018-09-26 · TA获得超过294个赞
知道小有建树答主
回答量:488
采纳率:83%
帮助的人:161万
展开全部
"hello"; //000000000022FE40
buf;//0000000000000040
p;//已知,可打印知道:printf("\np=%ld",p);
p(已知?变量指针指向buf数组指针)->buf(数组指针0000000000000040指向常量指针)->"hello"(常量指针000000000022FE40装载"hello");
//指针指向示意;
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式