百易时代C++面试题

来源:互联网 发布:爱福窝效果图制作软件 编辑:程序博客网 时间:2024/05/17 03:39

1:以下三条语句分别输出什么s

       charstr1[] = "abc";

       charstr2[] = "abc";

       constchar str3[] = "abc";

       constchar str4[] = "abc";

       constchar *str5 = "abc";

       constchar *str6 = "abc";

                    

2     以下代码中的连个sizeof的用法有问题吗?

       voidUpperCase(char str[])

       {

              for(size_t i = 0;i < sizeof(str)/sizeof(str[0]);++i)

              {

                     if('a'<=str[i]&&str[i]<='z')

                     str[i]-=('a' - 'A');                        

              }

       }

                           

       charstr[] = "aBcDe";

       cout<< "str字符长度"<<sizeof(str)/sizeof(str[0])<<endl;

       UpperCase(str);

       cout<< str << endl;

             

3     非C++内建型别A和B,在那种情况下B能隐式转化成A;

             

4    以下代码有什么问题

       structTest{

              Test(int){}

              Test(){};

              void fun(){}

              };

                    

       voidmain(void)

       {

              Test a(1);

              a.fun();

              Test b();

              b.fun();

       }

                    

5     以下代码有什么问题

       cout<<(true?1:"0")<<endl;

                    

6:    下面这段代码编译能通过吗?

       unsignedint const size1 = 2;

              char str1[size1] ;

       unsignedint temp = 0;

              cin>>temp;

       unsignedint const size2 = temp;

              char str2[size2];

7:    以下反向遍历array数组的方法有什么错误?

       vectorarray;

       array.push_back(1);

       array.push_back(2);

       array.push_back(3);

                    

       for(vector::size_typei = array.size()-1;i>0;--i)

       {

              cout << array[i] <<endl;

       }

8 以下代码中的输出语句能输出吗?

       struct  CLS

       {

              int m_i;

              CLS(int i):m_i(i){};

              CLS()

              {

                     CLS(0);

              }

       };

       CLSobj;

       cout<< obj.m_i <<endl;

                    

9     以下两条输出语句分别输出什么?

       floata = 1.0f;

       cout<< (int)a << endl;

       cout<< (int &)a << endl;

       cout<< boolalpha << ((int)a == (int &)a) << endl;

             

       floatb = 0.0f;

       cout<< (int)b << endl;

       cout<< (int &)b << endl;

       cout<< boolalpha << ((int)a == (int &)a) << endl;

0 0
原创粉丝点击