发布于 2014-09-26 00:20:01 | 241 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

网易(163)

网易公司(NASDAQ:NTES),是中国领先的互联网技术公司,也是中国主要门户网站,和新浪网、搜狐网、腾讯网并称为“中国四大门户网站”。网易在开发互联网应用、服务及其它技术方面始终保持中国业内界的领先地位。


本文是2014年网易 C/C++工程师笔试题,感兴趣的同学参考下.

1. #i nclude < filename.h >和#i nclude “filename.h” 有什么区别?

  答:对于#i nclude < filename.h >,编译器从标准库路径开始搜索filename.h

  对于#i nclude “filename.h”,编译器从用户的工作路径开始搜索filename.h

2. 在C++ 程序中调用被C 编译器编译后的函数,为什么要加extern “C”?

  答:C++语言支持函数重载,C 语言不支持函数重载。函数被C++编译后在库中的名字与C 语言的不同。假设某个函数的原型为: void foo(int x, int y);

  该函数被C 编译器编译后在库中的名字为_foo , 而C++ 编译器则会产生像_foo_int_int 之类的名字。

  C++提供了C 连接交换指定符号extern“C”来解决名字匹配问题。

 3. 一个类有基类、内部有一个其他类的成员对象,构造函数的执行顺序是怎样的?

  答:先执行基类的(如果基类当中有虚基类,要先执行虚基类的,其他基类则按照声明派生类时的顺序依次执行),再执行成员对象的,最后执行自己的。

4. New delete 与malloc free 的区别

  答:用malloc 函数不能初始化对象,new 会调用对象的构造函数。Delete 会调用对象的destructor,而free 不会调用对象的destructor.

  5. Struct 和class 的区别

  答:struct 中成员变量和成员函数默认访问权限是public,class 是private

 6.请问下面程序有什么错误?

  int a[60][250][1000],i,j,k;

  for(k=0;k<=1000;k++)

  for(j=0;j<250;j++)

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

  a[i][j][k]=0;

  答:把循环语句内外换一下

7. 请写出下列代码的输出内容

  #include <.stdio.h>

  main()

  {

  int a,b,c,d;

  a=10;

  b=a++;

  c=++a;

  d=10*a++;

  printf("b,c,d:%d,%d,%d",b,c,d);

  return 0;

  }

  答:10,12,120

8. 写出BOOL,int,float,指针类型的变量a 与零的比较语句。

  答: BOOL : if ( !a )

  int : if ( a == 0)

  float : const EXPRESSION EXP = 0.000001

  if ( a < EXP && a >-EXP)

  pointer : if ( a != NULL)

9.已知strcpy 函数的原型是:

  char *strcpy(char *strDest, const char *strSrc);

  其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数,请编写函数 strcpy

  答:

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

  {

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

  return NULL ;

  if ( strDest == strSrc)

  return strDest ;

  char *tempptr = strDest ;

  while( (*strDest++ = *strSrc++) != ‘\0’)

  ;

  return tempptr ;

  }

10.写一个函数找出一个整数数组中,第二大的数。

  答案:

  const int MINNUMBER = -32767 ;

  int find_sec_max( int data[] , int count) //类似于1 4 4 4这样的序列将认为1是第二大数

  {

  int maxnumber = data[0] ;

  int sec_max = MINNUMBER ;

  for ( int i = 1 ; i < count ; i++)

  {

  if ( data[i] > maxnumber )

  {

  sec_max = maxnumber ;

  maxnumber = data[i] ;

  }

  else

  {

  if ( data[i] > sec_max )

  sec_max = data[i] ;

  }

  }

  return sec_max ;

  }



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务