类似都市猎人的小说:C语言面试题集锦
来源:百度文库 编辑:偶看新闻 时间:2024/05/09 11:50:41
1、
int k=0;
while (k=1) {k++;}
A:循环一次
B:循环无数次
C:语法错误
D:不循环
答案:B
2、
char *a="Hello";
char *b="Hello";
if (a==b)
else
cout<<"akjgouo"< 问输出??
答案:dklajkl
3、
class _Student
{
public:
}
_Student student;
student.a=3.5;
student.b="A";
问错误???
答案:b为char型,被赋予一个字符串。
4、
int i,a[5],*p=a;
for (i=0;i<5;i++)
{ p++;
}
问错误???
答案:没做出来
第二部分:
Here is a program in ANSI Standard C:
double sum, a[20];
int i;
/*
* Some code to initialize array a with legitimate
* floating point values whose sum is less than "maximum double".
*/
sum = 0.0;
for (i = 0; i < 20; i++)
sum += a[i];
printf("%e ", sum);
sum = 0.0;
i = 20;
while (i--)
sum += a[i];
printf("%e ", sum);
Question:
Will the 2 "printed" values: 1) always be the same? if so, explain why.
2) always be different? if so, explain why.
3) sometimes be the same and sometimes different? if so, give an
example.
Please be as complete as possible.
数组未初始化,值是不确定的,选3
第三部分:
1.改错(5分)
void test()
{
}
答:数组越界char str[11];
2.改错(5分)
void test()
{
}
答:修改 strcpy(str, str1 )为strcpy(str1,str);
3.读程序,写出结果(5分)
int sum(int a)
{
}
int main()
{
}
答:8,10,12,14...
4.读程序,写出结果(5分)
int main()
{
}
答:2,3因为c++,所以先得到2,再输出3.
5.读程序,写出结果(10分,选做)
#define STRCPY(a, b)
int main()
{
}
答:var1 = var2
6.(10分)不用除法(即不能使用"/"号)和库函数,计算285 / 16的商和余数, 要求效率尽量高.
写得比较仓促,将就着看看吧。
7.(15分)编写字符串反转函数:strrev.要求时间和空间效率都尽量高.
(测试用例:输入"abcd",输出应为"dcba")
函数原型为:
char* strrev(char* dest, char* src);
提示:dest和src可能是同一个字符串.
void StrReverse( char *dest, char* sour )
{
}
int main( void )
{
}
8.(15分)编写将字符串转换成整数的函数atoi,只处理输入字符串仅由0-9,'-','+',和空格的情况.
函数原型为:
int atoi(char* str);
提示:如果字符串不能构成一整数,可以直接返回0.但是对于以空格开始的字符串应特殊处理.
答:
int atoi(char* str)
{
}
这个是060715这天写的,算是慢慢完成我的任务吧。
9.(30分)编写一组单链表操作函数.链表的结构如下:
struct ListNode
{
};
链表节点以id的从小到大排列,当id相等时,节点顺序没有约定,谁在前都可以.
要求编写的函数有:
遍历函数:返回cur下一个节点, 如果没有更多的节点, 返回0;
struct ListNode* ListNext(struct ListNode* cur);
插入函数:将newNode插入到head链表中,然后返回newNode的前一节点,
如果newNode已经在链表中,返回0.
struct ListNode* ListInsert(struct ListNode* head, struct ListNode* newNode);
删除函数:从head中删除theNode节点.返回theNode的前一节点.
如果theNode不在链表中,返回0;
struct ListNode* ListRemove(struct ListNode* head, struct ListNode* theNode);
答:
这个可以参见数据结构相关的书,我就不再写一遍了。
满分100, 时间90分钟