通碟是什么意思:阿里云面试总结 - zhangxinrun的专栏 - CSDN博客
来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 17:22:23
电话问题1:构造和析构函数中的虚函数调用;
答案:虚函数可以在构造函数和析构函数中调用,但虚函数此时是静态绑定;而非动态绑定。
电话问题2:C++中的异常可不可以是引用;
答案:异常可以是引用,并且效率高。电话问题3:TCP状态中的close_wait是什么状态;答案:close_wait状态是被动关闭方的一个状态,此时是半关闭状态,被关闭方收到了Fin包,并且发送了fin包的ack,等待上层应用结束连接。
电话问题4:排序算法的时间复杂度;
答案:最好是nLogn,其他的上网搜索。
面试问题1.atoi函数编写;
答案:
自己写的atoi函数----(注意:自己定义的atoi函数和库的atoi函数一样的时候,抛出异常时会引起异常退出,个人认为是异常没有不知道被那个函数抛出,所以coredump)
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const unsigned int SIGN_BIT = 0x1 << 31;
bool isDigit(const char ch)
{
if (ch <= '9' && ch >= '0')
{
return true;
}
return false;
}
int atoi_i(const char *str)
{
assert(str != NULL);
while (' ' == *str){ str++; }
int result = 0;
bool signFlag = false;
if ('+' == *str)
{
if (false == isDigit(*++str)) throw "input format error!";
}
else if ('-' == *str)
{
if (false == isDigit(*++str)) throw "input format error!";
signFlag = true;
}
else if (*str > '9' || *str < '0')
{
throw "input format error!";
}
do
{
result = result * 10 + *str++ - '0';
if ((result & SIGN_BIT) != 0)
{
throw "overflow error!";
}
}
while (isDigit(*str));
if (true == signFlag)
{
result = -result;
}
return result;
}
int main(int argc, char *argv[])
{
char input[1024];
while (1)
{
try
{
cout << "Input Array:";
cin >> input;
printf("exchange:%d\n", atoi_i(input));
}
catch (const char *p)
{
cout <<"Error Info:" << p << endl;
}
catch ( ... )
{
cout << "test" << endl;
}
}
return 0;
}本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangxinrun/archive/2010/12/01/6048695.aspx
面试问题2.sizeof和空类;
答案:class CBase
{
int a;
char *p;
};
那么运行cout<<"sizeof(CBase)="<{
};
运行cout<<"sizeof(CBase)="<{
public:
CBase(void);
virtual ~CBase(void);
private:
int a;
char *p;
};
再运行:sizeof(CBase)=12C++ 类中有虚函数的时候有一个指向虚函数的指针(vptr),在32位系统分配指针大小为4字节”。那么继承类呢?第四步:基类就是上面的了不写了class CChild :
public CBase
{
public:
CChild(void);
~CChild(void);
private:
int b;
};
运行:cout<<"sizeof(CChild)="<面试问题3.(1)对象只允许在堆上创建,(2)对象只允许在栈上创建;
答案:class HeapOnly
{
public:
HeapOnly()
{
cout<<"constructor. "< }
void destroy()
{
delete this;
}
private:
~HeapOnly(){}
};
int main()
{
HeapOnly *p = new HeapOnly;
p->destroy();
HeapOnly h;
h.Output();
return 0;
}
#include
using namespace std;
class StackOnly
{
public:
StackOnly()
{
cout<<"constructor." < }
~StackOnly()
{
cout<<"destructor." < }
private:
void *operator new (size_t);
};
int main()
{
StackOnly s; //okay
StackOnly *p = new StackOnly; //wrong
return 0;
}本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangxinrun/archive/2010/12/03/6052551.aspx面试问题4.在一个不知道升序还是降序的数据组中查找一个给定的数,
个人想法:1.根据数组的首尾比较,判断数组的序列形式;2.折半查找算法。答案:#include
#include
using namespace std;
static bool flag = true;
bool intCompare(int value1, int value2)
{
return (value1 > value2) == flag;
}
int binary_search_i(int a[], int value, int start, int end)
{
if (start > end) return -1;
int pos = (start + end)/ 2;
if (value == a[pos])
{
return pos;
}
else if (intCompare(value, a[pos]))
{
return binary_search_i(a, value, pos + 1, end);
}
else
{
return binary_search_i(a, value, start, pos - 1);
}
}
int binary_search(int a[], int value, int n)
{
assert((a != NULL) && (n > 0));
if ((n == 1) || (a[0] == a[n - 1]))
{
if (a[0] == value)
{
return 0;
}
else
{
return -1;
}
}
if (a[0] < a[n - 1])
{
flag = true;
}
else
{
flag = false;
}
int temp = binary_search_i(a, value, 0, n - 1);
while ((temp > 0) && (a[temp] == a[temp - 1]))
{
--temp;
}
return temp;
}
int main()
{
//int a[] = {1, 3, 5, 7, 7, 7, 7, 7, 7, 7, 9, 10, 11};
int a[] = {11, 10, 9, 7, 7, 7, 7, 7, 5, 3, 1};
int arrayNum = sizeof(a) / sizeof(int);
for(int i = 0; i < arrayNum; ++i)
{
printf("a[%d]=%d\t", i, a[i]);
}
printf("\n");
int value = 0;
while(1)
{
printf("Input search value:");
scanf("%d", &value);
printf("Pos in array:%d\n", binary_search(a, value, arrayNum));
}
return 0;
}
面试问题5.那些算法是稳定排序,那些算法是不稳定排序。答案:上网上搜索一下。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangxinrun/archive/2010/12/05/6056315.aspx
答案:虚函数可以在构造函数和析构函数中调用,但虚函数此时是静态绑定;而非动态绑定。
电话问题2:C++中的异常可不可以是引用;
答案:异常可以是引用,并且效率高。电话问题3:TCP状态中的close_wait是什么状态;答案:close_wait状态是被动关闭方的一个状态,此时是半关闭状态,被关闭方收到了Fin包,并且发送了fin包的ack,等待上层应用结束连接。
电话问题4:排序算法的时间复杂度;
答案:最好是nLogn,其他的上网搜索。
面试问题1.atoi函数编写;
答案:
自己写的atoi函数----(注意:自己定义的atoi函数和库的atoi函数一样的时候,抛出异常时会引起异常退出,个人认为是异常没有不知道被那个函数抛出,所以coredump)
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const unsigned int SIGN_BIT = 0x1 << 31;
bool isDigit(const char ch)
{
if (ch <= '9' && ch >= '0')
{
return true;
}
return false;
}
int atoi_i(const char *str)
{
assert(str != NULL);
while (' ' == *str){ str++; }
int result = 0;
bool signFlag = false;
if ('+' == *str)
{
if (false == isDigit(*++str)) throw "input format error!";
}
else if ('-' == *str)
{
if (false == isDigit(*++str)) throw "input format error!";
signFlag = true;
}
else if (*str > '9' || *str < '0')
{
throw "input format error!";
}
do
{
result = result * 10 + *str++ - '0';
if ((result & SIGN_BIT) != 0)
{
throw "overflow error!";
}
}
while (isDigit(*str));
if (true == signFlag)
{
result = -result;
}
return result;
}
int main(int argc, char *argv[])
{
char input[1024];
while (1)
{
try
{
cout << "Input Array:";
cin >> input;
printf("exchange:%d\n", atoi_i(input));
}
catch (const char *p)
{
cout <<"Error Info:" << p << endl;
}
catch ( ... )
{
cout << "test" << endl;
}
}
return 0;
}本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangxinrun/archive/2010/12/01/6048695.aspx
面试问题2.sizeof和空类;
答案:class CBase
{
int a;
char *p;
};
那么运行cout<<"sizeof(CBase)="<
};
运行cout<<"sizeof(CBase)="<
public:
CBase(void);
virtual ~CBase(void);
private:
int a;
char *p;
};
再运行:sizeof(CBase)=12C++ 类中有虚函数的时候有一个指向虚函数的指针(vptr),在32位系统分配指针大小为4字节”。那么继承类呢?第四步:基类就是上面的了不写了class CChild :
public CBase
{
public:
CChild(void);
~CChild(void);
private:
int b;
};
运行:cout<<"sizeof(CChild)="<
答案:class HeapOnly
{
public:
HeapOnly()
{
cout<<"constructor. "<
void destroy()
{
delete this;
}
private:
~HeapOnly(){}
};
int main()
{
HeapOnly *p = new HeapOnly;
p->destroy();
HeapOnly h;
h.Output();
return 0;
}
#include
using namespace std;
class StackOnly
{
public:
StackOnly()
{
cout<<"constructor." <
~StackOnly()
{
cout<<"destructor." <
private:
void *operator new (size_t);
};
int main()
{
StackOnly s; //okay
StackOnly *p = new StackOnly; //wrong
return 0;
}本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangxinrun/archive/2010/12/03/6052551.aspx面试问题4.在一个不知道升序还是降序的数据组中查找一个给定的数,
个人想法:1.根据数组的首尾比较,判断数组的序列形式;2.折半查找算法。答案:#include
#include
using namespace std;
static bool flag = true;
bool intCompare(int value1, int value2)
{
return (value1 > value2) == flag;
}
int binary_search_i(int a[], int value, int start, int end)
{
if (start > end) return -1;
int pos = (start + end)/ 2;
if (value == a[pos])
{
return pos;
}
else if (intCompare(value, a[pos]))
{
return binary_search_i(a, value, pos + 1, end);
}
else
{
return binary_search_i(a, value, start, pos - 1);
}
}
int binary_search(int a[], int value, int n)
{
assert((a != NULL) && (n > 0));
if ((n == 1) || (a[0] == a[n - 1]))
{
if (a[0] == value)
{
return 0;
}
else
{
return -1;
}
}
if (a[0] < a[n - 1])
{
flag = true;
}
else
{
flag = false;
}
int temp = binary_search_i(a, value, 0, n - 1);
while ((temp > 0) && (a[temp] == a[temp - 1]))
{
--temp;
}
return temp;
}
int main()
{
//int a[] = {1, 3, 5, 7, 7, 7, 7, 7, 7, 7, 9, 10, 11};
int a[] = {11, 10, 9, 7, 7, 7, 7, 7, 5, 3, 1};
int arrayNum = sizeof(a) / sizeof(int);
for(int i = 0; i < arrayNum; ++i)
{
printf("a[%d]=%d\t", i, a[i]);
}
printf("\n");
int value = 0;
while(1)
{
printf("Input search value:");
scanf("%d", &value);
printf("Pos in array:%d\n", binary_search(a, value, arrayNum));
}
return 0;
}
面试问题5.那些算法是稳定排序,那些算法是不稳定排序。答案:上网上搜索一下。 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhangxinrun/archive/2010/12/05/6056315.aspx
阿里云面试总结 - zhangxinrun的专栏 - CSDN博客
面试与程序员 - wmnothing的专栏 - CSDN博客
IT十年总结 - ShaHuShaBoJue的专栏 - CSDN博客
Eclipse插件安装总结 - huxin1的专栏 - CSDN博客
宝宝 javaweb 学习总结 - 马文涛的专栏 - CSDN博客
bbbbbbj的专栏 - CSDN博客
vc++ - lonelytreebjfu的专栏 - CSDN博客
ASCII码表 - heruibin的专栏 - CSDN博客
tcp cwnd - linweixuan的专栏 - CSDN博客
RTMP是什么 - Thinkor2k8的专栏 - CSDN博客
手机知识 - whpeace的专栏 - CSDN博客
指针Guide - chinahai的专栏 - CSDN博客
数据库触发器 - chinayuan的专栏 - CSDN博客
中国式管理 - wmnothing的专栏 - CSDN博客
IE捉迷藏 - bluesqsr的专栏 - CSDN博客
USB有关的编程 - sanshao27的专栏 - CSDN博客
一篇很实用的入门教程 - ph9527的专栏 - CSDN博客
软件开发的效率 - wmnothing的专栏 - CSDN博客
VB的浮点数处理 - zdingyun的专栏 - CSDN博客
程序员的面包 - ShaHuShaBoJue的专栏 - CSDN博客
工作的5个阶段 - bingling525的专栏 - CSDN博客
变参函数的实现 - 菜鸟的专栏 - CSDN博客
DLL Hell的解决方案 - jonathandj的专栏 - CSDN博客
IM服务器的架构 - sanfengshou的专栏 - CSDN博客