Alex's Blog
===========================================================
===========================================================
题目如下
http://blog.itpub.net/post/670/22687

转自:ledon@spicy-girl


小弟做了一下,请大家指正有没有错。
1。找错
void test1()
{
char string[10]; //string的长度应该设为11,要给''留出位置
char* str1="0123456789";
strcpy( string, str1);
}

void test1()
{
char string[10], str1[10];
for(I=0; I<10; I++ ) //变量I没定义,增加int I;
//I不能取到9,同上一题一样要给''留出位置
//应该改成for(I=0; I<9; I++)
{
str1[i] = 'a'; //变量i没定义,改为str1[I] = 'a';
}
//此处要加上结尾标识 str1[i]='';
strcpy(string, str1);
}

void test3(char* str1)
{
char string[10];
if( strlen(str1) <= 10 ) //同样的问题,str1的长度不能超过9;改为
// if( strlen(str1) < 10 )
{
strcpy(string, str1);
}
}


2。
#define MAX_SRM 256

DSN get_SRM_no()
{
static int SRM_no; //静态变量没有初始化
int I;

for(I=0; I { //此处不知所云
SRM_no %= MAX_SRM;
if( MY_SRM.state == IDLE ) //MY_SRM IDLE未定义
{
break;
}
}
if( I>=MAX_SRM)
return NULL_SRM; //NULL_SRM未定义
else
return SRM_no;
}

3。
8,10,12,14,16

4.
题目有错吧? 是不是应该改成这样:
int func( int a )
{
int b;
switch( a )
{
case 1: b=30;
case 2: b=20;
case 3: b=16;
default: b=0;
}
return b;
}

如果是这样func(1) = 0;


5.
   2

6.
sizeof(int) *12 = 4*12 = 64 (byte)

7.
应该是考取模运算的,没什么技巧。 代码略



alexclark 发表于:2005.03.21 13:29 ::分类: ( 所见即所得 ) ::阅读:(10424次) :: 评论 (5)
我就不懂啦。 [回复]

6.
sizeof(int) *12 = 4*12 = 64 (byte)

这个64怎么来的????

borenbao 评论于: 2005.11.17 13:14
参考答案(基于alexclark的答案, 待指正) [回复]

1。找错
void test1()
{
char string[10]; //string的长度应该设为11,要 给''留出位置。准确点说是要给字符串中止符‘’留出位置,要不然string不知道该在哪儿结束。
char* str1="0123456789";
strcpy( string, str1);
}

void test2()
{
char string[10], str1[10];
for(I=0; I

charmian 评论于: 2005.11.28 11:55
回复borenbao [回复]

1.给字符串留出末尾的‘’的位置
6.sizeof(int) = 4,你可以编个小程序测试一下

alexclark 评论于: 2005.11.29 10:16
补充 [回复]

1.给字符串留出末尾的字符‘0’的位置

alexclark 评论于: 2005.11.29 10:19
[回复]

int func( int a )
{
int b;
switch( a )
{
case 1: b=30;
case 2: b=20;
case 3: b=16;
default: b=0;
}
return b;
}

如果是这样func(1) =30 20 16 0
因为没有在case后加break

xxz 评论于: 2006.02.23 02:12

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)

 authimage


自我介绍
切换风格
新闻聚合
博客日历
文章归档...
最新发表...
最新评论...
最多阅读文章...
最多评论文章...
博客统计...
Blog信息
网站链接...