每个人都想当老板,马云说,“有梦想是好的,万一实现了呢”。
但是,不管你信不信,世界上,老板要比员工少。
找工作难,做好工作更难。
面试是你拿到工作的机会,
有面试就难免有笔试,公司的面试题目我认为在一年当中不会有很大改动的,所以可以参考下
以下是收集本人在这个月的面试时间里遇到的一些值得分享的面试题目,但愿能帮到同行或其它求职者!
为保护相关公司的隐私,本人在此不提供真实公司名字,若需要了解的,可以加本人QQ1258029407,获得进一步提示!!!!
company one: xxxxxxxxxxxxxxxxxx 性质:游戏
1、写出socket编程类型和基本函数及步骤。
2、如何获取当前文件的路径。
3、反转链表。
4、求1+2+3+........+n(如果你直接写 return n*(1+n)*1/2,而且还坚持的认为自己的答案对了,恭喜你,你可以回去等通知了(面试官的潜台词:你可以OUT了)。。。。)
5、智力题(由于本人智商不高,认为还是很难的)
(1)水杯倒水问题:给两个不同容量的杯子,要你想办法量出给定量的水(不是很难,运气好很快就找到思路)
(2)有若干条质地均匀的绳子,烧一条要1小时,问你如何想办法通过烧绳子来记1小时50分钟的时间
。。。。。还有很多暂时记不得了。。。。。。
company two: xxxxxxxxxxxxxxxxxx 性质:办公设备系统
1、c语言内存分配问题
NO.1
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str,"hello world");
printf(str);
}
请问运行 Test 函数后会是什么样的结果?
NO.2
char *GetMemory(void)
{
char p[] = hello world;
retrun p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
问题同 NO.1
NO.3
void GetMemory(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str,100);
strcpy(str,"hello");
printf(str);
}
问题同 NO.1
NO.4
void Test(void)
{
char *str = (char *)malloc(100);
strcpy(str,"hello");
free(str);
if(str != NULL)
{
strcpy(str,"world");
printf(str);
}
}
问题同 NO.1
我对以上问题的分析:
NO.1:程序首先申请一个 char 类型的指针 str,并把 str 指向 NULL(即 str 里存的是 NULL
的地址, *str 为 NULL 中的值为0), 调用函数的过程中做了如下动作:
1 、申请一个 char 类型的指针 p,
2、把 str 的内容 copy 到了 p 里(这是参数传递过程中系统所做的) ,
3、为 p 指针申请了 100 个空间,
4、返回 Test 函数.最后程序把字符串 hello world 拷贝到 str 指向的内存空间里. 到这里错
误出现了!
str 的空间始终为 NULL 而并没有实际的空间.深刻理解函数调用的第 2 步,将不难发现问
题所在! (注意:传递的参数和消除的参数)
NO.2:程序首先申请一个 char 类型的指针 str,并把 str 指向 NULL.调用函数的过程中做了
如下动作:
1申请一数组 p[]并将其赋值为 hello world(数组的空间大小为 12),
2返回数组名 p 付给 str 指针(即返回了数组的首地址).
那么这样就可以打印出字符串" hello world"了么?当然是不能的!
因为在函数调用的时候漏掉了最后一步. 也就是在第2步 return 数组名后,函数调用还要
进行一步操作,也就是释放内存空间. 当一个函数被调用结束后它会释放掉它里面所有的变
量所占用的空间.所以数组空间被释放掉了,也就是说 str 所指向的内容将不确定是什么东
西.
NO.3:正确答案为可以打印出 hello.但内存泄漏了! 需要用 free()函数进行释放。
NO.4:申请空间,拷贝字符串,释放空间.前三步操作都没有任何问题.到 if 语句里的判
断条件开始出错了,因为一个指针被释放之后其内容并不是 NULL,而是一个不确定的值. 所
以 if 语句永远都不能被正确执行.这也是著名的"野"指针问题.所以我们在编写程序释放
一个指针之后一定要人为的将指针付成 NULL. 这样就会避免出现"野"指针的出现.有人
说"野"指针很可怕,会带来意想不到的错误.
company three: xxxxxxxxxxxxxxxxxx性质:Web后端(该公司题目:全英文,呵呵呵呵)
{
unsigned int i;
char *a[] = {"a", "b", "c", "d", "e"};
for (i = 5; i>=0; --i)
{
printf("\n");
printf(a[i]);
printf("\n");
}
}
char *p = str ;
int n = 10;
请计算
(1)sizeof (str ) = ?
(2)sizeof ( p ) = ?
(3)sizeof ( n ) = ?
void Foo ( char str[100]){
请计算
sizeof( str ) = ?(4)
}
void *p = malloc( 100 );
请计算
sizeof ( p ) = ?(5)
答:(1)25 (2)4 (3) 4 (4)4 (5)4
(6)
double *(*dub)[2][3] //double **dub
sizeof(dub) //&dub *dub **dub ***dub ****dub
if (NULL == hMutex)
{
return false;
}
int err = GetLastError();
if (ERROR_ALREADY_EXISTS == err)
{
return false;
}
(2、引用初始化后不可改变值,指针可以改变。
(3、引用传参不需重新分配内存,指针需要重新分配内存。
#include <vector>
#include<algorithm>
using namespace std;
class CObject
{
public:
int m_a, m_b;
CObject(int a, int b): m_a(a), m_b(b)
{
}
CObject()
{
}
~CObject()
{
}
bool operator < (const CObject& obj);
bool operator > (const CObject& obj);
bool operator == (const CObject& obj);
CObject& operator = (const CObject& obj);
};
void Merge(vector<CObject>& dst,vector<CObject> src)
{
vector<CObject> temp;
int i, j, nDst, nSrc;
nDst = dst.size ();
nSrc = src.size ();
for (j = 0; j < nSrc; ++j)
{
for (i = 0; i < nDst; ++i)
{
if (src[j].m_a >= dst[i].m_a)
break;
}
if (i >= nDst)
temp.push_back(src[j]);
}
vector<CObject>::iterator it1, it2, it;
it = dst.end ();
it1 = temp.begin ();
it2 = temp.end ();
dst.insert (it, it1, it2);
sort(dst.begin (), dst.end ());
}
void ShowObject(vector<CObject>& obj)
{
for (int i = 0; i < obj.size (); ++i)
{
cout << obj[i].m_a << " " << obj[i].m_b << endl;
}
cout << "_____________________________________" << endl;;
}
int main()
{
int i;
CObject dst[5];
CObject src[5];
for (i = 0; i < 5; ++i)
dst[i] = CObject(i+5, i+5);
for (i = 0; i < 5; ++i)
src[i] = CObject(i+2, i+2);
vector<CObject> dstObj(dst, dst + 5);
ShowObject(dstObj);
vector<CObject> srcObj(src, src + 5);
ShowObject(srcObj);
Merge(dstObj, srcObj);
ShowObject(dstObj);
return 0;
}
bool CObject::operator < (const CObject& obj)
{
return (m_a < obj.m_a) && (m_b < obj.m_b);
}
bool CObject::operator > (const CObject& obj)
{
return (m_a > obj.m_a) && (m_b > obj.m_b);
}
bool CObject::operator == (const CObject& obj)
{
return (m_a == obj.m_a) && (m_b == obj.m_b);
}
CObject& CObject::operator = (const CObject& obj)
{
m_a = obj.m_a;
m_b = obj.m_b;
return *this;
}
#include<iostream>
#include <vector>
#include<algorithm>
using namespace std;
class CObject
{
private:
int m_a, m_b;
public:
CObject(int a, int b):m_a(a),m_b(b)
{}
};
//不改CObject类的实现,将a值赋给m_a
void SetValue(CObject* obj, int a, int b)
{
if (obj != NULL)
{
delete[] obj;
obj = NULL;
}
obj = new CObject(a,b);
}
int main()
{
CObject* pObj = new CObject(1,2);
//DoTo:
SetValue(pObj,2,2);
delete[] pObj;
}
#include <string>
using namespace std;
union DATA{
int a[5];
char c;
double d;
};
struct data{
int a;
DATA cow;
char c;
double d;
}too;
DATA MAX;
int main(int arg,char* arc[]){
cout << sizeof(MAX) << endl;
cout << sizeof(data) << endl;
return 0;
}
#include <string>
using namespace std;
struct Base{
int b;
Base(){
cout << "Base gouzao!" << endl;
}
~Base(){
cout << "Base xigou!" << endl;
}
void show(){
cout << "I am Base!" << endl;
};
};
struct A : public Base{
int a;
A(){
cout << "A gouzao!" << endl;
}
~A(){
cout << "A xigou!" << endl;
}
void show(){
cout << "I am A!" << endl;
};
};
int main(int arg,char* arc[]){
A a;
a.show();
return 0;
}
private:
int a;
char *b;
public:
A(){
cout << "A 构造" << endl;
}
A(const A &a){
this->a = a.a;
this->b = a.b; //浅拷贝
//b = new char[strlen(a.b)+1]; //深拷贝
//strcpy(b,a.b);
cout << "A 拷贝构造" << endl;
}
~A(){
//delete[] b;
cout << "A 析构" << endl;
}
};
3、“” 和 <>头文件的区别
当你包含一个头文件时,编译时,需要找到那个头文件,使用<>这种方式,编译器查找的时候,会在编译器的安装目录的标准库中开始查找,""这种方式,会在当前的工程所在的文件夹开始寻找,也就是你的源程序所在的文件夹。
4、二分查找
int tFind(int a[],int t,int low,int hight){ int mid,temp; if (low > hight) return -1; mid = (low + hight) / 2; temp = a[mid]; if(temp == t){ printf("在位置%d找到%d.\n",mid,t); return t; } if (temp > t){ return tFind(a,t,low,mid-1); }else{ return tFind(a,t,mid+1,hight); } } int main () { int a[] = {0,1,2,3,4,5,6,7,8,9}; tFind(a,9,0,9); return 0; }
company:12
1、运算符优先级
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main ()
{
int k = 10,j = 10,i = 3;
k *= i + j;
cout << "k=" << k << endl; //130
return 0;
}
company13:
1、比较两个float a,float b的大小:
if(-0.000001 <= a-b && a-b <=0.000001)
return true;
2、string类的拷贝构造函数、赋值=函数、析构函数
3、写一个日期类
答:注意年月日的输入限制