• 2021-04-14
    有如下的程序: #include #include using namespace std; class MyString { public: MyString(const char *s); ~MyString() {delete []data;} protected: unsigned len; char * data; }; MyString::MyString(const char *s) { len = strlen(s); data = new char[len+1]; strcpy(data,s); } int main() { MyString a("C++ Programming"); MyString b(a); return 0; } 在运行上面的程序时出错,出错的原因是( )。
  • 没有定义实现深层复制(深拷贝)的拷贝构造函数

    内容

    • 0

      DateTime.Parse(myString);这行代码有什么问题?

    • 1

      中国大学MOOC:"如下程序的输出是什么____#include #include using namespace std;struct MyException : public exception{ const char * what () const throw () { return "C++ Exception"; }};int main(){ try { throw MyException(); } catch(MyException& e) { std::cout << "MyException" << std::endl; } catch(std::exception& e) { std::cout<<"exception" << std::endl; }}";

    • 2

      对于如下程序:#include &#91;stdio.h&#93; int s(char *,char *); int main(){ char a&#91;20&#93;; char b&#91;10&#93;; char *p; char *q; int i; p=a; q=b; scanf("%s%s",a,b); i=s(a,b); printf("%d",i);} int s(char *s,char *t){ while(*s!='\0' && *t!='\0'){ if(*s= =*t){ s++; t++; } else return *s-*t; } return *s-*t;}如果输入流是12 13,程序的输出是什么? A: -1 B: 1 C: 0 D: 2

    • 3

      中国大学MOOC: 下列程序的运行结果是 。 #include<iostream>using namespace std;char *fun(char *str, char c){ while ( *str!=’\0’) if(*str==c) return (str); else str++; return (NULL);}void main(){ char s [80] = “warrior”, *p; p=fun(s, ‘r’); if(p) cout<<p<<endl;p=fun(s, ‘i’); if(p) cout<<p<<endl;p=fun(s, ‘b’); if(p) cout<<p<<endl;}

    • 4

      以下C的程序片段输出的结果是( )。char p&#91;20&#93;; char *s = "Data"; int length = strlen(s); int i; for (i = 0; i &lt; length; i++) p[i] = s&#91;length - i&#93;; printf("%s", p);[/i] A: 输出是空白 B: data C: atad D: adat