程序员笔试面试题.docx

上传人:b****5 文档编号:6716188 上传时间:2023-01-09 格式:DOCX 页数:24 大小:26.38KB
下载 相关 举报
程序员笔试面试题.docx_第1页
第1页 / 共24页
程序员笔试面试题.docx_第2页
第2页 / 共24页
程序员笔试面试题.docx_第3页
第3页 / 共24页
程序员笔试面试题.docx_第4页
第4页 / 共24页
程序员笔试面试题.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

程序员笔试面试题.docx

《程序员笔试面试题.docx》由会员分享,可在线阅读,更多相关《程序员笔试面试题.docx(24页珍藏版)》请在冰豆网上搜索。

程序员笔试面试题.docx

程序员笔试面试题

[计算机]笔试面试题整理

面试

本帖最后由locust_j于2009-8-513:

45编辑推荐~

附件名称:

笔试面试题整理.txt

附件大小:

14KB

附件备注:

附件内容已贴出

现在的公司招聘,都要笔试面试.如果你不是那种编程功底非常深厚的人,又不好好准备一番,在笔试面试中往往会处于被动局面.虽然有些笔试题是故意为难我们,有点钻牛角尖.但是很多笔试题面试题确实能够很好地看出我们的基础.

在这里,我就略去那些钻牛角尖的题.从csdn论坛我近半年的收集中选出10道有代表性的题目,难度基本上是逐渐加大.对数组,指针,数据结构,算法,字符串,文件操作等问题都有覆盖.主要以c语言的实现为主,也有c++的题.大家可以先做做这10道题,测试一下自己的水平.

1.下面这段代码的输出是多少(在32位机上).

char*p;

char*q[20];

char*m[20][20];

int(*n)[10];

structMyStruct

{

chardda;

doubledda1;

inttype;

};

MyStructk;

printf("%d%d%d%d",sizeof(p),sizeof(q),sizeof(m),sizeof(n),sizeof(k));

2.

(1)

chara[2][2][3]={{{1,6,3},{5,4,15}},{{3,5,33},{23,12,7}}};

for(inti=0;i<12;i++)

printf("%d",_______);

在空格处填上合适的语句,顺序打印出a中的数字

(2)

char**p,a[16][8];

问:

p=a是否会导致程序在以后出现问题?

为什么?

3.用递归方式,非递归方式写函数将一个字符串反转.

函数原型如下:

char*reverse(char*str);

4.strcpy函数和memcpy函数有什么区别?

它们各自使用时应该注意什么问题?

5.写一个函数将一个链表逆序.

一个单链表,不知道长度,写一个函数快速找到中间节点的位置.

写一个函数找出一个单向链表的倒数第n个节点的指针.(把能想到的最好算法写出).

6.用递归算法判断数组a[N]是否为一个递增数组。

7.

有一个文件(名为a.txt)如下,每行有4项,第一项是他们的名次,写一个c程序,将五个人的名字打印出来.并按名次排序后将5行数据仍然保存到a.txt中.使文件按名次排列每行.

2,07010188,0711,李镇豪,

1,07010154,0421,陈亦良,

3,07010194,0312,凌瑞松,

4,07010209,0351,罗安祥,

5,07010237,0961,黄世传,

8.写一个函数,判断一个unsignedchar字符有几位是1.

写一个函数判断计算机的字节存储顺序是升序(little-endian)还是降序(big-endian).

9.微软的笔试题.

ImplementastringclassinC++withbasicfunctionalitylikecomparison,concatenation,inputandoutput.Pleasealsoprovidesometestcasesandusingscenarios(samplecodeofusingthisclass).

PleasedonotuseMFC,STLandotherlibrariesinyourimplementation.

10.有个数组a[100]存放了100个数,这100个数取自1-99,且只有两个相同的数,剩下的98个数不同,写一个搜索算法找出相同的那个数的值.(注意空间效率时间效率尽可能要低).

这十道题还是能够看出自己的水平如何的.如果你能不假思索地做出这10道题,估计去国外大公司是没有问题了,呵呵.

答案我在整理中,以后陆续发布.................

下面有些题也不错,可以参考.

1.下面的代码输出是什么,为什么?

voidfoo(void)

{

unsignedinta=6;

intb=-20;

(a+b>6)?

puts(">6"):

puts("<=6");//puts为打印函数

}

输出>6.

就是考察隐式转换.int型变量转化成unsignedint, b成了正数.

2.b)运行下面的函数会有什么结果?

为什么?

voidfoo(void)

{

charstring[10],str1[10];

inti;

for(i=0;i<10;i++)

{

str1='a';

}

strcpy(string,str1);

printf("%s",string);

}

首先搞清strcpy函数的实现方法,

char*strcpy(char*strDest,constchar*strSrc)

{

 if((strDest == NULL) || (strSrc == NULL))

  throw"Invalidargument(s)";

 char*strDestCopy = strDest;

 while((*strDest++ = *strSrc++) !

= '\0');

 returnstrDestCopy;

}

由于str1末尾没有'\0’结束标志,所以strcpy不知道拷贝到何时结束.

printf函数,对于输出char*类型,顺序打印字符串中的字符直到遇到空字符('\0')或已打印了由精度指定的字符数为止.

下面是微软的两道笔试题....

3.ImplementastringclassinC++withbasicfunctionalitylikecomparison,concatenation,inputandoutput.Pleasealsoprovidesometestcasesandusingscenarios(samplecodeofusingthisclass).

PleasedonotuseMFC,STLandotherlibrariesinyourimplementation.

我的实现方案如下,这道题真地对c++的主要特性都进行了较好地考察.

String.h:

#ifndefSTRING_H

#defineSTRING_H

#include

usingnamespacestd;

classString{

public:

String();

String(intn,charc);

String(constchar*source);

String(constString&s);

//String&operator=(char*s);

String&operator=(constString&s);

~String();

char&operator[](inti){returna;}

constchar&operator[](inti)const{returna;}//对常量的索引.

String&operator+=(constString&s);

intlength();

friendistream&operator>>(istream&is,String&s);//搞清为什么将>>设置为友元函数的原因.

//friendbooloperator<(constString&left,constString&right);

friendbooloperator>(constString&left,constString&right);//下面三个运算符都没必要设成友元函数,这里是为了简单.

friendbooloperator==(constString&left,constString&right);

friendbooloperator!

=(constString&left,constString&right);

private:

char*a;

intsize;

};

#endif

String.cpp:

#include"String.h"

#include

#include

String:

:

String(){

a=newchar[1];

a[0]='\0';

size=0;

}

String:

:

String(intn,charc){

a=newchar[n+1];

memset(a,c,n);

a[n]='\0';

size=n;

}

String:

:

String(constchar*source){

if(source==NULL){

a=newchar[1];

a[0]='\0';

size=0;

}

else

{size=strlen(source);

a=newchar[size+1];

strcpy(a,source);

}

}

String:

:

String(constString&s){

size=strlen(s.a);//可以访问私有变量.

a=newchar[size+1];

//if(a==NULL)

strcpy(a,s.a);

}

String&String:

:

operator=(constString&s){

if(this==&s)

return*this;

else

{

delete[]a;

size=strlen(s.a);

a=newchar[size+1];

strcpy(a,s.a);

return*this;

}

}

String:

:

~String(){

delete[]a;//

}

String&String:

:

operator+=(constString&s){

intj=strlen(a);

intsize=j+strlen(s.a);

char*tmp=newchar[size+1];

strcpy(tmp,a);

strcpy(tmp+j,s.a);

delete[]a;

a=tmp;

return*this;

}

intString:

:

length(){

returnstrlen(a);

}

main.cpp:

#include

#include"String.h"

usingnamespacestd;

booloperator==(constString&left,constString&right)

{

inta=strcmp(left.a,right.a);

if(a==0)

returntrue;

else

returnfalse;

}

booloperator!

=(constString&left,constString&right)

{

return!

(left==right);

}

ostream&operator<<(ostream&os,String&s){

intlength=s.length();

for(inti=0;i

//os<

os<

returnos;

}

Stringoperator+(constString&a,constString&b){

Stringtemp;

temp=a;

temp+=b;

returntemp;

}

booloperator<(constString&left,constString&right){

intj=0;

while((left[j]!

='\0')&&(right[j]!

='\0')){

if(left[j]

returntrue;

else

{

if(left[j]==right[j]){

j++;

continue;

}

else

returnfalse;

}

}

if((left[j]=='\0')&&(right[j]!

='\0'))

returntrue;

else

returnfalse;

}

booloperator>(constString&left,constString&right)

{inta=strcmp(left.a,right.a);

if(a>0)

returntrue;

else

returnfalse;

}

istream&operator>>(istream&is,String&s){

delete[]s.a;

s.a=newchar[20];

intm=20;

charc;

inti=0;

while(is.get(c)&&isspace(c));

if(is){

do{s.a=c;

i++;

/*if(i>=20){

cout<<"Inputtoomuchcharacters!

"<

exit(-1);

}*/

if(i==m-1){

s.a='\0';

char*b=newchar[m];

strcpy(b,s.a);

m=m*2;

s.a=newchar[m];

strcpy(s.a,b);

delete[]b;

}

}

while(is.get(c)&&!

isspace(c));

//如果读到空白,将其放回.

if(is)

is.unget();

}

s.size=i;

s.a='\0';

returnis;

}

intmain(){

Stringa="abcd";

Stringb="www";

//Stringc(6,b);这么写不对.

Stringc(6,'l');

Stringd;

Stringe=a;//abcd

Stringf;

cin>>f;//需要输入...

Stringg;

g=a+b;//abcdwww

if(a

cout<<"a

else

cout<<"a>=b"<

if(e==a)

cout<<"e==a"<

else

cout<<"e!

=a"<

b+=a;

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

return0;

}

4.Implementasingle-directionlinkedlistsortingalgorithm.Pleasefirstdefinethedatastructureoflinkedlistandthenimplementthesortingalgorithm.

5.编写一个函数,返回两个字符串的最大公串!

例如,“adbccadebbca”和“edabccadece”,返回“ccade”

联想笔试题

  1.设计函数intatoi(char*s)。

intatoi(constchar*nptr);

函数说明

atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。

返回值返回转换后的整型数。

#include

#include

intmyAtoi(constchar*s){

intresult=0;

intflag=1;

inti=0;

while(isspace(s))

i++;

if(s=='-'){

flag=-1;

i++;

}

if(s=='+')

i++;

while(s!

='\0'){

if((s>'9')||(s<'0'))

break;

intj=s-'0';

result=10*result+j;

i++;

}

result=result*flag;

returnresult;

}

intmain(){

char*a="-1234def";

char*b="+1234";

inti=myAtoi(a);

intj=myAtoi(b);

printf("%d\n",i);

printf("%d",j);

return0;

}

  2.inti=(j=4,k=8,l=16,m=32);printf(“%d”,i);输出是多少?

  3.解释局部变量、全局变量和静态变量的含义。

  4.解释堆和栈的区别。

  5.论述含参数的宏与函数的优缺点。

  普天C++笔试题

  1.实现双向链表删除一个节点P,在节点P后插入一个节点,写出这两个函数。

  2.写一个函数,将其中的\t都转换成4个空格。

  3.Windows程序的入口是哪里?

写出Windows消息机制的流程。

  4.如何定义和实现一个类的成员函数为回调函数?

  5.C++里面是不是所有的动作都是main()引起的?

如果不是,请举例。

  6.C++里面如何声明constvoidf(void)函数为C程序中的库函数?

  7.下列哪两个是等同的

  intb;

  Aconstint*a=&b;

  Bconst*inta=&b;

  Cconstint*consta=&b;

  Dintconst*consta=&b;

  8.内联函数在编译时是否做参数类型检查?

  voidg(base&b){

  b.play;

  }

  voidmain(){

  sons;

  g(s);

  return;

  }

华为笔试题

  1.请你分别画出OSI的七层网络结构图和TCP/IP的五层结构图。

  2.请你详细地解释一下IP协议的定义,在哪个层上面?

主要有什么作用?

TCP与UDP呢?

  3.请问交换机和路由器各自的实现原理是什么?

分别在哪个层次上面实现的?

  4.请问C++的类和C里面的struct有什么区别?

  5.请讲一讲析构函数和虚函数的用法和作用。

  6.全局变量和局部变量有什么区别?

是怎么实现的?

操作系统和编译器是怎么知道的?

  7.8086是多少位的系统?

在数据总线上是怎么实现的?

Sony笔试题

  1.完成下列程序

  *

  *.*.

  *..*..*..

  *...*...*...*...

  *....*....*....*....*....

  *.....*.....*.....*.....*.....*.....

  *......*......*......*......*......*......*......

  *.......*.......*.......*.......*.......*.......*.......*.......

  #include

  #defineN8

  intmain()

  {

  inti;

  intj;

  intk;

  ---------------------------------------------------------

  ||

  ||

  ||

  ---------------------------------------------------------

  return0;

  }

  2.完成程序,实现对数组的降序排序

  #include

  voidsort();

  intmain()

  {

  intarray[]={45,56,76,234,1,34,23,2,3};//数字任//意给出

  sort();

  return0;

  }

  voidsort()

  {

  ____________________________________

  ||

  ||

  |-----------------------------------------------------|

  }

  3.费波那其数列,1,1,2,3,5……编写程序求第十项。

可以用递归,也可以用其他方法,但要说明你选择的理由。

  #include

  intPheponatch(int);

  intmain()

  {

  printf("The10this%d",Pheponatch(10));

  return0;

  }

  intPheponatch(intN)

  {

  --------------------------------

  ||

  ||

  --------------------------------

  }

  4.下列程序运行时会崩溃,请找出错误并改正,并且说明原因。

  #include

  #include

  typedefstruct{

  TNode*left;

  TNode*right;

  intvalue;

  }

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 育儿理论经验

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1