程序员面试试题
来自:jinhill,时间:2006-10-18 17:12:00
1、头文件中的 ifndef/define/endif 干什么用?
2、#include <filename.h> 和 #include “filename.h” 有什么区别?
3、const 有什么用途?(请至少说明两种)
4、在c++ 程序中调用被 c编译器编译后的函数,为什么要加 extern
“c”声明?
5、简述以下两个for循环的优缺点
for (i=0; i<n; i++)
{
if (condition)
dosomething();
else
dootherthing();
}
/***************************** /
if (condition)
{
for (i=0; i<n; i++)
dosomething();
}
else
{
for (i=0; i<n; i++)
dootherthing();
}
有关内存的思考题
/****************************/
void getmemory(char *p)
{
p = (char *)malloc(100);
}
void test(void)
{
char *str = null;
getmemory(str);
strcpy(str, "hello world");
printf(str);
}
请问运行test函数会有什么样的结果?
**********************************************/
char *getmemory(void)
{
char p[] = "hello world";
return p;
}
void test(void)
{
char *str = null;
str = getmemory();
printf(str);
}
请问运行test函数会有什么样的结果?
/********************************************/
void getmemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
void test(void)
{
char *str = null;
getmemory(&str, 100);
strcpy(str, "hello");
printf(str);
}
请问运行test函数会有什么样的结果?
/*******************************************/
void test(void)
{
char *str = (char *) malloc(100);
strcpy(str, “hello”);
free(str);
if(str != null)
{
strcpy(str, “world”);
printf(str);
}
}
请问运行test函数会有什么样的结果?
*********************************/
编写strcpy函数
已知strcpy函数的原型是
char *strcpy(char *strdest, const char *strsrc);
其中strdest是目的字符串,strsrc是源字符串。
(1)不调用c++/c的字符串库函数,请编写函数 strcpy
(2)strcpy能把strsrc的内容复制到strdest,为什么还要char * 类型的
返回值?
/**************************************************/
编写类string的构造函数、析构函数和赋值函数
已知类string的原型为:
class string
{
public:
string(const char *str = null); // 普通构造函数
string(const string &other); // 拷贝构造函数
~ string(void); // 析构函数
string & operate =(const string &other); // 赋值函数
private:
char *m_data; // 用于保存字符串
};
请编写string的上述4个函数。
--------------------------------------------------------------------------------------------
发布者信息:jinhill 邮件
主页
IP:211.88.4....
--------------------------------------------------------------------------------------------
本站所载文章力求原创,部分资料转载自网上,转载文章均要求发布者注明出处。
若您认为某些文章侵犯了您的权益,请通知我们,我们将在最短的时间内删除有关文章。
如果您对文章内容有任何心得或异议,请到锦山工控论坛发表高见!
|