人人网实习招聘笔试题目整理

来源:互联网 发布:mac电脑潮壁纸 编辑:程序博客网 时间:2024/06/02 09:42

今天在北邮参加了人人网霸笔,是c++相关的知识。将部分试题整理如下:要求写输出内容

1)void TestLength(const char* array1,chararray2[])

{

       cout<<sizeof(array1)<<strlen(array1)<<"/n";

       cout<<sizeof(array2)<<strlen(array2)<<"/n";

      

}

       const char* array1 = "123456";

       chararray2[] = "12345";

       cout<<sizeof(array1)<<strlen(array1)<<"/n";

       cout<<sizeof(array2)<<strlen(array2)<<"/n";

       TestLength(array1,array2);


// 这道题是区别sizeof() strlen()这两个函数的。

Csdn上对于sizeof()说明如下:

When applied to a statically dimensionedarray, sizeof returns the size of the entire array. The sizeofoperator cannot return the size of dynamically allocated arrays or externalarrays

当是静态数组时大小为数组大小,档位动态数组或者指针时,返回参数本身的字节数。

Strlen():returns the number of charactersin string, excluding the terminal NULL

该题的正确答案是 46 6546 45

2) 这是第二题

struct A

{  A(constchar* str)

       {

              staticA a = "hello";

              printf("[%s]",str);

       }

A& operator=(const char* str)

{     printf("==%s",str);

       return*this;

}

};

A a0 = "what";

Main()

{

       Aa1 = "test";

       Aa2 = "hot";

    return;

}

考点1:类赋值函数和拷贝运算区别

 如果对象在申明的同时马上进行的初始化操作,则称之为拷贝运算例如:
       class1 A("af"); class1 B=A;
  此时其实际调用的是B(A)这样的浅拷贝操作。

 如果对象在申明之后,在进行的赋值运算,我们称之为赋值运算。例如:
        class1 A("af"); class1 B;
        B=A;
此时实际调用的类的缺省赋值函数B.operator=(A);

考点2:静态对象在main 函数执行之前就进行初始化

对这道题自己还是有些迷惑,还请高人指点!

正确答案是[hello][what][test][hot].

原创粉丝点击