上海龙凤1314 shlf

网易校园招聘C/C++笔试题

时间:2018-12-31 12:00:00 资料大全 我要投稿

上海龙凤1314 shlf网易校园招聘C/C++笔试题

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

网易校园招聘C/C++笔试题

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

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

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

  答:C++语言支持函数重载,C 语言不支持函数重载,

网易校园招聘C/C++笔试题

上海龙凤1314 shlf。函数被C++编译后在库中的名字与C 语言的不同。假设某个函数的原型为: void foo(int x, int y);

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

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

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

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

  4. New delete 与malloc free 的区别

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

  5. Struct 和class 的区别

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

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

上海龙凤1314 shlf   int a[60][250][1000],i,j,k;

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

上海龙凤1314 shlf   for(j=0;j<250;j++)

上海龙凤1314 shlf   for(i=0;i<60;i++)

上海龙凤1314 shlf   a[i][j][k]=0;

上海龙凤1314 shlf   答:把循环语句内外换一下

上海龙凤1314 shlf   7. 请写出下列代码的输出内容

  #include <.stdio.h>

  main()

  {

上海龙凤1314 shlf   int a,b,c,d;

  a=10;

  b=a++;

  c=++a;

  d=10*a++;

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

上海龙凤1314 shlf   return 0;

  }

  答:10,12,120

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

资料共享平台

网易校园招聘C/C++笔试题》(http://gdyhdog.com)。

  答: BOOL : if ( !a )

  int : if ( a == 0)

  float : const EXPRESSION EXP = 0.000001

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

  pointer : if ( a != NULL)

上海龙凤1314 shlf   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)

上海龙凤1314 shlf   return NULL ;

上海龙凤1314 shlf   if ( strDest == strSrc)

上海龙凤1314 shlf   return strDest ;

上海龙凤1314 shlf   char *tempptr = strDest ;

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

  ;

  return tempptr ;

  }

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

  答案:

  const int MINNUMBER = -32767 ;

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

  {

  int maxnumber = data[0] ;

上海龙凤1314 shlf   int sec_max = MINNUMBER ;

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

  {

  if ( data[i] > maxnumber )

  {

上海龙凤1314 shlf   sec_max = maxnumber ;

上海龙凤1314 shlf   maxnumber = data[i] ;

  }

  else

  {

上海龙凤1314 shlf   if ( data[i] > sec_max )

  sec_max = data[i] ;

  }

  }

上海龙凤1314 shlf   return sec_max ;

  }

【网易校园招聘C/C++笔试题】相关文章:

1.网易校园招聘C/C++笔试题

2.网易校园招聘C/C++笔试题

3.网易C++笔试题

4.TCL集团校园招聘C/C++方向笔试题

5.网易校园招聘笔试题

6.C/C++笔试题

7.网易校园招聘杭州Java笔试题

8.C++笔试题