小弟刚刚起步,请大家看个问题

时间:2008-05-22 05:02:01   来源:论坛整理  作者:  编辑:chinaitzhe
非常感谢你能抽出时间看我的问题,谢谢,祝你生活过的愉快
下面的代码几个输出都不一样,请你说下各个是什么意思,为什么?
#include <stdio.h>
main()
{
char c;
c='d';
printf("the &c %%p is %p\n",&c);
printf("the &c %%u is %u\n",&c);
printf("the &c %%s is %s\n",&c);
printf("the &c %%c is %c\n",&c);
printf("the c %%p is %p\n",c);
printf("the c %%u is %u\n",c);
printf("the c %%s is %s\n",c);
printf("the c %%c is %c\n",c);
fflush(stdin);
getchar();
}
网友回复:%P
%u
%s
%c
是格式控制符,用来将同一个二进制的数据以不同的格式输出。

网友回复:谢谢wuyu637 那么各个都是什么样的输出
网友回复:请阅读MSDN相关部分
网友回复:%p:输出指针值或地址;
%u:以无符号十进制形式输出整数;
%s:输出字符串;
%c:以字符形式输出,只输出一个字符;

网友回复:谢谢mly0904 那可以说一下我上面那个是输出正确的c的地址吗
网友回复:运行一下就知道了!
网友回复:汗.局部变量的内存地址分配在栈上,是在运行时地址是在一定的范围上的,不是你说多少就多少.
网友回复:谢谢大家,什么意思,感觉很深奥,能不能说的简单点
网友回复:%p:输出指针值或地址;
%u:以无符号十进制形式输出整数;
%s:输出字符串;
%c:输出字符.
运行结果:
the &c %p is 0023FF6F
the &c %u is 2359151
the &c %s is d?#
the &c %c is o
the c %p is 00000064
the c %u is 100
之后提示出错!~

网友回复:main()
{
char c;
c='d';
printf("the &c %%p is %p\n",&c);//把c的指针或地址值输出
printf("the &c %%u is %u\n",&c); //以无符号十进制形式输出整数;
printf("the &c %%s is %s\n",&c); //输出&c所指向的地址空间的字符串的内容(字符串是以“\0”结束)
printf("the &c %%c is %c\n",&c); //把&c的地址值转为ASCLL码输出。
printf("the c %%p is %p\n",c);
printf("the c %%u is %u\n",c);
printf("the c %%s is %s\n",c);//地址异常了。地址跑到一边了
printf("the c %%c is %c\n",c);
fflush(stdin);
getchar();
}
网友回复:谢谢大家的帮忙,小弟有了一定的了解
关键字:小弟,刚刚,起步,问题,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面