目前本站已有 十几万 份求职资料啦!


编程员面试题目

10-15 23:59:20 来源:http://www.qz26.com 笔试题目   阅读:8832
导读: { public: String(const char *str = NULL); // 通用构造函数 String(const String &another); // 拷贝构造函数 ~ String(); // 析构函数 String & operater =(const String &rhs); // 赋值函数 private: char *m_data; // 用于保存字符串 }; 尝试写出类的成员函数实现。 答案: String::String(const char *str) { if ( str == NULL ) //strlen在参数为NULL时会抛异常才会有这步判断 { m_data = new char[1] ; m_data[0] = '\0' ; } else { m_data = new char[strlen(str) + 1];
编程员面试题目,标签:银行笔试题目,企业笔试题目,http://www.qz26.com
    {
    public:
    String(const char *str = NULL); // 通用构造函数
    String(const String &another); // 拷贝构造函数
    ~ String(); // 析构函数
    String & operater =(const String &rhs); // 赋值函数
    private:
    char *m_data; // 用于保存字符串
    };

    尝试写出类的成员函数实现。

    答案:

    String::String(const char *str)
    {
    if ( str == NULL ) //strlen在参数为NULL时会抛异常才会有这步判断
    {
    m_data = new char[1] ;
    m_data[0] = '\0' ;
    }
    else
    {
    m_data = new char[strlen(str) + 1];
    strcpy(m_data,str);
    }

    }

    String::String(const String &another)
    {
    m_data = new char[strlen(another.m_data) + 1];
    strcpy(m_data,other.m_data);
    }


    String& String::operator =(const String &rhs)
    {
    if ( this == &rhs)
    return *this ;
    delete []m_data; //删除原来的数据,新开一块内存
    m_data = new char[strlen(rhs.m_data) + 1];
    strcpy(m_data,rhs.m_data);
    return *this ;
    }


    String::~String()
    {
    delete []m_data ;
    }

    ③网上流传的c++笔试题汇总
    1.求下面函数的返回值(微软)

    int func(x)
    {
    int countx = 0;
    while(x)
    {
    countx ++;
    x = x&(x-1);
    }
    return countx;
    }

    假定x = 9999。 答案:8

    思路:将x转化为2进制,看含有的1的个数。

    2. 什么是“引用”?申明和使用“引用”要注意哪些问题?

    答:引用就是某个目标变量的“别名”(alias),对应用的操作与对变量直接操作效果完全相同。申明一个引用的时候,切记要对其进行初始化。引用声明完毕后,相当于目标变量名有两个名称,即该目标原名称和引用名,不能再把该引用名作为其他变量名的别名。声明一个引用,不是新定义了一个变量,它只表示该引用名是目标变量名的一个别名,它本身不是一种数据类型,因此引用本身不占存储单元,系统也不给引用分配存储单元。不能建立数组的引用。

上一页  [1] [2] [3]  下一页


Tag:笔试题目银行笔试题目,企业笔试题目求职笔试面试 - 笔试题目
【字号: 】 【打印】 【关闭
下一条:编程笔试题目
《编程员面试题目》相关文章
最新更新
推荐热门
联系我们 | 网站地图 | 财务资料 | 范文大全 | 求职简历 | 财会考试 | 成功励志
Copyright 二六求职资料网 All Right Reserved.
1 2 3 4 5 6 7 8 9 10