有如下程序: #include #include using namespace std; class XCD{ char*a: int b; public:

admin2020-11-11  17

问题 有如下程序:   
    #include
    #include
    using namespace std;   
    class XCD{
          char*a:
          int b;  
    public:   
            XCD(char*aa,int bb){
            a-new char[strlen(aa)+1];
            strcpy(a,aa);
            b=bb;   
    }
    char*Geta(){return a;}
    int Getb(){return b;}
    };
    int main(){
    char*p1=ˊˊabedˊˊ,*p2=ˊˊweirongˊˊ;
    int d1=6,d2=8;
    XCD x(p1,d1),y(p2,d2);
    cout<    return 0;   
    }
    运行时的输出结果是(    )。

选项 A、12
B、16
C、14
D、11

答案A

解析 由类XCD的定义可知,成员函数Geta()返回的是字符串的长度,Getb()返回的是参数b的值。在主函数中 strlen(x.Geta())的值等于4,y.Getb()的值等于8,所以输出两者的和为12。
转载请注明原文地址:https://kaotiyun.com/show/WMyp777K
0

相关试题推荐
最新回复(0)