| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 742 人关注过本帖
标题:求助:关于strlen()和sizeof()的问题
取消只看楼主 加入收藏
hrp313
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-8-23
收藏
 问题点数:0 回复次数:0 
求助:关于strlen()和sizeof()的问题

//Question1
#include <stdio.h>
#include <string.h>

void main()
{
int x = 35;
char str[10];

printf("x = %d,strlen(str)=%d,sizeof(str)=%d\n",x,strlen(str),sizeof(str));
}
此时输出 x = 35,strlen(str)=13,sizeof(str)=10 对strlen(str)=13不解
如果把前两行调个位结果又不一样如下:
//Question2
#include <stdio.h>
#include <string.h>

void main()
{
char str[10];
int x = 35;

printf("x = %d,strlen(str)=%d,sizeof(str)=%d\n",x,strlen(str),sizeof(str));
}
这时输出 x = 35,strlen(str)=15,sizeof(str)=10 对strlen(str)=13
这个更不可思议了
//Question 3
#include <stdio.h>
#include <string.h>

void main()
{
int x = 35;
char str[10];

strcpy(str,"www.it315.org"/*共13个字母*/);

printf("x = %d,strlen(str)=%d,sizeof(str)=%d\n",x,strlen(str),sizeof(str));
}
此时输出x = 103,strlen(str)=13,sizeof(str)=10 对x的值不可思议
//Question4
void main()
{
char str[10];
int x = 35;

strcpy(str,"www.it315.org"/*共13个字母*/);

printf("x = %d,strlen(str)=%d,sizeof(str)=%d\n",x,strlen(str),sizeof(str));
}
此时编译无错,但执行出错,但还是能输出x = 35,strlen(str)=13,sizeof(str)=10
所有这些都不太明白,请高手指点,感激不尽!

搜索更多相关主题的帖子: str sizeof include void int 
2006-08-24 00:08
快速回复:求助:关于strlen()和sizeof()的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011589 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved