菜鸟问指针问题:

xinteng 2006-04-01 09:23:13
程序如下:我想用char的二级指针一个字节一个字节的输出int指针变量的地址,
为什么总是不行??结果却不是一个字节一个字节???
#include<stdio.h>
#include<conio.h>
main()
{ char **p;
int y=0, * intp;
clrscr();
intp=&y;
p=&intp;
printf("\n\t%5x,%5x,%5x,%5x",&y,intp,*p,*(p+1));
}
...全文
125 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
iolia 2006-04-01
  • 打赏
  • 举报
回复
呵呵,慢了
iolia 2006-04-01
  • 打赏
  • 举报
回复
这样应该就可以了,不是char **+1而是char *+1
#include<stdio.h>
#include<stdlib.h>
int main()
{ char *p;
int y=0, *intp;
intp=&y;
p=(char * )(intp);
printf("\n%5p,%5p,%5p,%5p",&y,intp,p,(p+1));
printf("\n");
system("pause");
return 0;

}
sankt 2006-04-01
  • 打赏
  • 举报
回复
指针变量占据4个字节的空间

我不是很理解:
一个字节一个字节输出指针变量的地址??
findcsdn 2006-04-01
  • 打赏
  • 举报
回复
#include<stdio.h>

main()
{ char *p;
int y=0, * intp;
intp = &y;
p = (char*)(&intp);

printf("%5x, %x,%x,%x,%x \n", &y, *p, *(p+1), *(p+2), *(p+3));
}


显示位数自己调整一下
xinteng 2006-04-01
  • 打赏
  • 举报
回复
to(sankt)
我看了一下,还是不能一个字节一个字节输出指针变量的地址啊???
sankt 2006-04-01
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>
int main()
{ char **p;
int y=0, *intp;

intp=&y;
p=(char ** )intp;
printf("\n%5p,%5p,%5p,%5p",&y,intp,p,(p+1));
printf("\n");
system("pause");
return 0;

}

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧