偶前几天的C++面试题(省略了编程题),有兴趣的朋友看看

 

偶前几天的C++面试题(省略了编程题),有兴趣的朋友看看!!!!一同分享,呵呵


C++
笔试题(满分100分,时间40分钟
)
将答案写在指定的答卷纸内,不能在考卷上作答。


一. 填空(每小题4分,共40分)。


1
  struct  stru_type
{  int  a;
double  d;
char  *pch;
stru_type  *stru;
};
double  x;
int  n;
sizeof(stru_type)+sizeof(x)+sizeof(n)= ______
.   

2
  32位的操作系统中,
char *pst=”this a string”;
      (1)  sizeof(pst)=_______

      (2)  strlen(pst)=_______


3
  int  a[6]={10,3,2, 7,9,5};
      *a*(a+2)[1]=______


4
简述一下const#define的异同。


5
void main()
      {  char ch[10], *pstr=”this a test”:
          strcpy(ch, pstr);
          cout < <ch < <endl;
      }
   
请问ch的输出结果是什么,为什么?


6
C++4种存储类型,分别是自动、外部、静态和寄存器型。请回答以下问题:

      int  a; 
      static  int  sa;

执行以上程序,asa的值是多少?为什么?


7
类的继承是面向对象一个非常重要的概念,继承方式有公有继承、保护继承和私有继承,请运用类的继承访问权限的理论,完成下面问题:



class  A
    {  public:
      A();
      fun1();
      protected:
      fun2();
};
class B:protected A
{  public:
    B();
    fun3();
    protected:
    fun4();
    private:
    int m_i;
}:

(1)
派生类B的成员可否访问fun1fun2? 并说明理由。

(2)
派生类B的对象可否访问fun2? 如果不能,请说明理由。

(3)
B的对象可否访问fun4? 如果不能,请说明理由。


8
  class  A
{  public:
  A(){ b++; }
  void sets(int i){ s = i; }
  int getb(){ return b; }
  int gets(){ return s; }
  private:
  static int b;
  int s;
};
int A::b=0;
void main()
{
A  a[5];
for(int j=0; j <5; j++)
  a[j].sets(j);
for(int i=0; i <5;i++)

cout < <”a[“ < <i < <”].b=” < <a[i ].getb() < <endl;
    cout < <”a[“ < <i < <”].s=” < <a[i].gets() < <endl;
}
            }

请写出执行以上程序后输出的结果。


9
.数据20, 8, 12, 4, 30, 9依次入栈,不可能的出栈顺序是______

A  12
3094820  B  8930412 20
C  201249830  C  20493012
8

10
写出下面程序的输出结果。

void fun(char **p)
{
*p=*p+3;
}

void main()
{
char *ps="tested function";
fun(&ps);
cout < <ps < <endl;
}

二、改错题.,指出程序中的错误并加以纠正(每小题5分,共10分)。

1
  void main()
{  int  maxsize=20,  a[maxsize]={10,5,12,30,45,7,50,63,2};
          for(int i=0; i <5; i++)
          cout < <a[i] < <endl;
}
 
        2
  #define  N  50
void main()

          int  i=0, count=0;
          char *pst=”this is a tested string”, str[N];
          str=pst;
          while(str[i]!=’/ 0’ )
        {
            if(str[i]==’t’)
            count++;
            i++;
          }
      }


三、程序阅读题, 写出程序执行结果(每小题10分,共20分).



1
void  main()
{
int arr[]={6,7,8,9,10};
      int *ptr=arr;
*(ptr++)=*(ptr++)+100;
  printf("%d,%d",*ptr,*(++ptr));
}

2
class  A
{
        public:
            A(int a)
        { 
m_v=a;
          cout < <"constructor  A  called" < <endl;
          }
~A()
{
cout < <"destructor  A  called" < <endl;
}
void fun1()
{
cout < <"A's fun1() called" < <endl;
}
int  fun2(int b)
{
  m_v=b; 
return m_v;
}
            protected:
              int m_v;
};
class  B:public A
{
            public:
      B(int b, int n):A(n)
        {
m_b=b; 
        cout < <"constructor B called" < <endl;
      }

~B()
{
cout < <"destructor B called" < <endl;
}
int  fun3(int m)
{
return(A::m_v+m);
}
            private:
            int  m_b;
};

void  main()
{  B  b(10, 9);
            A  *pa;
            pa=&b;
            cout < <pa->fun2(5) < <endl;
            cout < <b.fun3(20) < <endl;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值