参考答案:几道C语言面试题(华为)
作者: alexclark(http://alexclark.itpub.net)发表于: 2005.03.21 13:29
分类: 所见即所得
出处: http://alexclark.itpub.net/post/670/22962
---------------------------------------------------------------
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.
应该是考取模运算的,没什么技巧。 代码略



