更多“说出下面几个函数的区别: private void test(string str){…} private void test(ref strin ”相关问题
  • 第1题:

    void GetMemory(char *p){p = (char *)malloc(100);}void Test(void) {char *str

    = NULL;GetMemory(str); strcpy(str, "hello world");printf(str);}请问运行 Test 函数

    会有什么样的结果?


    正确答案:
     

  • 第2题:

    Void GetMemory2(char **p, int num){*p = (char *)malloc(num);}void

    Test(void){char *str = NULL;GetMemory(&str, 100);strcpy(str, "hello"); printf(str); }请问

    运行Test 函数会有什么样的结果?


    正确答案:
     

  • 第3题:

    编写类 String 的构造函数、析构函数和赋值函数

    已知类 String的原型为:

    class String

    {

    public:

    String(const char *str = NULL); // 普通构造函数

    String(const String &other); // 拷贝构造函数

    ~ String(void); // 析构函数

    String & perate =(const String &other); // 赋值函数

    private:

    char *m_data; // 用于保存字符串

    };

    请编写 String的上述 4 个函数。


    正确答案:
     

  • 第4题:

    char *GetMemory(void){ char p[] = "hello world";return

    p; }void Test(void){char *str = NULL;str = GetMemory(); printf(str);}请问运行 Tes

    t 函数会有什么样的结果?


    正确答案:
     

  • 第5题:

    void Test(void){char *str = (char *)

    malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “

    world”); printf(str);}}请问运行 Test 函数会有什么样的结果?


    正确答案:
     

  • 第6题:

    下面程序的结果是 include class test{private: int num; publi

    下面程序的结果是 #include<iostream.h> class test{ private: int num; public: test( ); int getint( ) {return num;} ~test( );}; test::test( ) { num=0;} test::~test( ) { cout<<"Destructor is active"<<endl;} void

    A.Exiting main Destructor is active Destructor is active Destructor is active

    B.Exiting main Destructor is active Destructoris active

    C.Exiting main Destructoris active

    D.Exiting main


    正确答案:A
    解析:C++语言中析构函数是在程序退出不用该类的对象时进行调用。