为什么只谈一面?因为参加了一面才知道自己的水平!简历上的熟练和精通请慎重!
自我介绍就不用多说。
先上问题:
1、谈一下new和malloc的区别?
简单说了malloc只分配内存,不能创建对象。
2、析构函数的作用
销毁对象?应该是清理在构造函数中所申请的内存空间。
3、UML设计模式知道吗?有几种设计模式?
懵逼
4、存储器的构成?操作系统学过没有?MMySQL数据库的优点是什么?
懵逼
5、堆和栈的区别说一下
6、信号量的作用
7、linux内核了解吗?有几种锁?
我说的互斥锁和读写锁,考官说的是自旋锁
8、手撕代码:用数组实现栈
当时我一脸懵逼,只用链表写过栈,虽然原理一样,但是不会。还是用链表写的,考官直接说我根本没有理解他的意思,于是重新撕另外一个代码。
#include <iostream>
using namespace std;
#define Max 10
int stack[Max];
int top = -1;
void push(int value)
{
int i = 0;
if (top > Max - 1)
cout << "\nThe stack is full!\n";
else
{
cout << "Before push, the stack is top->bottom: \n";
if (top < 0)
cout << "It is empty." << endl;
else{
for (i = top; i >= 0; i--)
cout << stack[i] << " ";
cout << endl;
}
++top;
stack[top] = value;
for (int j = top; j >= 0; j--)
cout << stack[j] << " ";
cout << endl;
}
}
int pop()
{
int tmp;
int i;
if (top < 0)
{
cout << "The stack is empty" << endl;
return -1;
}
cout << "before pop" << endl;
for (i = top; i >= 0; i--)
cout << stack[i] << " ";
cout <<endl;
tmp = stack[top];
--top;
if (top < 0)
cout << "It is empty" << endl;
else
{
cout << "after pop" << endl;
for (i = top; i >= 0; i--)
cout << stack[i] << " ";
cout << endl;
}
return tmp;
}
int main()
{
push(1);
push(2);
push(3);
push(4);
pop();
return 0;
}
链表实现
#include <iostream>
#include <cstdio>
using namespace std;
typedef struct _node
{
int data;
struct _node *next;
}node, *pnode;
pnode phead = NULL;
int create(void)
{
// phead = (node *)malloc(sizeof(node));
phead = new node;
if (phead == NULL)
return -1;
return 0;
}
node *push(int val)
{
//node *p = (node *)malloc(sizeof(node));
node *p = new node;
p->data = val;
p->next = phead;
phead = p;
return phead;
}
int pop()
{
if (phead == NULL)
return -1;
node *p = NULL;
int ret = phead->data;
p = phead;
//free(p);
delete p;
return ret;
}
int main()
{
create();
push(10);
push(20);
push(30);
cout << pop() << endl;
return 0;
}
9、STL知道吗?写一个compare函数
已经不耐烦,要求5分钟写完,过了一分钟,问你到底会不会?我说不会,我觉得该肯定进不了2面,于是准备收拾东西走人,他又来一句你比较熟悉linux下的开发是吧?我再次懵逼,难道不该说你这么水,可以回去等通知吗(领盒饭)?又问了下面2个问题。
10、进程与线程的区别?
11、进程间通信的方式
上面2个问题,我没有按照书面的解释来,用的是项目中使用的理解来说的。面试官说了一句:恭喜你通过了一面,现在去综合面试区(2面)等待面试。
手撕代码那一关实在是最难熬的一关,还是基础问题,面试之前关于栈、队列部分的实现都是用链表做的,生无可恋!
发offer了!
10月卖身!