海硕科技C++职位面试

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 176 收藏 0 点赞 0 评论 0

1.tcp中send()两次recv要几次。换成udp又怎样。为什么。

tcp发送0字节的会收的到吗?udp又会如何?

makefile中=,:=,?=的区别?
tcp中怎么控制connection的连接超时。

2.写个循环双链表的代码,自己写。他提供几个函数名
3.关于进程间通信
4.智商题

 

笔试

1.int a[][2] = {{a,b},{c,d}}

  char **p = a;

  printf(“%sn”,*(p+1));

  p++;

 printf(“%sn”,*p + 1);

输出以下结果:

%s不能输出char 类型的变量。要抛出异常

 

 

可能结果:

1.提示 b c d 未定义   第一行缺少’;’

2.cd

b

 

 

 

2.string类,写出类函数

string

{

public:

 string(const char *str = NULL);

 string(const string &other);

 ~string(void);

 string &operator =( const string &other);

private:

  char *m_pstr;

}

/////////////////////

string::string(const char *str)

{

  If(str != NULL)

  {

    Int length = strlen(str);

    M_pstr = new char[length+1];

   Strcpy(m_pstr,str);

}

  Else

{

   M_pstr = new char[1];

*M_pstr = ‘’;

}

}

string ::string(const string &other)

{

   If(other.m_pstr != NULL)

{

Int length = strlen(str);

    M_pstr = new char[length+1];

   Strcpy(m_pstr,str);

}

  Else

  {

    M_pstr = new char[1];

*M_pstr = ‘’;

 

  }

}

string ::string::string(void)

{

    Free m_pstr;

}

string & string::operator =( const string &other)

{

   If(this == &other)

       Return *this;

   Free(m_pstr);

   If(other.m_pstr != NULL)

{

     //Free(m_pstr);

     Malloc(m_pstr,strlen(other.m_pstr)+1);

Strcpy(m_pstr, other.m_pstr);

}

   Else

        M_pstr = NULL;

Return *this;

 

}

3.利用递归实现输入1输入11,输入12输出1122

//正确答案

Void func(char *output)

{

   Char *p = output;

   If(*p != ‘’)

   {

        Printf(“%c%c”,*p,*p);

}

   Else

   {

       Printf(“nover!n”);

       Return ;

   }

   Func(++p);

}

 

  void printDoubleNum(int num)

  {

      Int i = 0;

      Int first = 0;

      Int second = 0;

      If(num/10 == 0)

      {

         Printf(“%d%d”,second);

          Fflush();

        Return ;

 

       }

      While(1)

      {

           If((first = num/Pow(10,i)) != 0)

{

   Second = first;

I++;

}

           Else 

               Break;

      }

      Printf(“%d%d”,second);

      Fflush();

      Int val = num – second*pow(10, i-1);

      printDoubleNum(val);

  }

4. void GetMemory(char *p) 

p = (char *)malloc(100); 

void Test(void)   

char *str = NULL; 

GetMemory(str);  

strcpy(str, “hello world”); 

printf(str); 

输出结果:  段错误         

为什么:      GetMemory不能传递动态内存      

5.char *p;

  char a[5][5];

  char *q = (char *)malloc(100);

  printf(“%dn”,sizeof(p));

printf(“%dn”,sizeof(a));

printf(“%dn”,sizeof(a[5][5]));

printf(“%dn”,sizeof(q));

输出结果:

4

25

1

4(因为q不是数组)

6.重载和重定义的区别

重载是在同一个类中,同一个函数名,因它们的参数的位置,参数的类型,排列顺序不一样,使在调用的时候根据不同情况调用不同的函数

 子类重新定义父类中有相同名称的非虚函数 ( 参数列表可以不同 ) 。

有加virtual 就叫做覆盖

 

7.结束线程和进程有哪些方式

结束线程:1。在函数中用return,能回到调用线程函数的线程。

          2.自线程内调用 用Thread_exit(void *exit_val);

          3.线程外面调用  terminate_thread(HANDLE ht)能结束标识为ht的线程

          4.主线程结束时。其它线程也不能存在

结束进程:1。在函数中用exit(),能结束进程。

          2.进程收到信号,而此信号没有处理,或是处理采取了结束进程的动作. 

 

8.说出MFC中有那些GDI的类

  CPen  画笔

  CBrush  画刷

  HFONT   字体

  HBITMAP 位图

  HPALETTE  调色板

  HRGN    区域 

  GDI内存(如做双缓冲用)

  DCcommplimap  

  CObject

评论列表
文章目录