挂面经、凉面经

20200708-头条,视频架构

问的很基础,但是回答的很稀烂

1. 允许多个进程同时对数据进行读操作,但是不允许读和写以及写和写操作同时发生。

一个整型变量 count 记录在对数据进行读操作的进程数量,一个互斥量 count_mutex 用于对 count 加锁,一个互斥量 data_mutex 用于对读写的数据加锁。

2. 

用变量a 给出下面的定义

1) 一个有10个指针的数组,该指针是指向一个整型数的;

2)  一个指向有10个整型数数组的指针;

3) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数;

4) 一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数;

3. 

  1. const A* a和 A const* a的区别是?
  2. volatile、mutable分别怎么用,有什么区别?
  3. 在C++ 程序中调用被 C 编译器编译后的函数,需要怎么处理一下?为什么?

4 .带答案(请填充位置的函数体)

#include <iostream>
#include <cstring>
using namespace std;
class C
{
public:
    C(int size) : i(size)
    {
        data = (char*)new char[i];
    }

    ~C()
    {
        //请填充
        if(data != NULL) {
            delete []data;
        }
    }

    C(const C& other) = delete;

    C(C&& other) = delete;

    C& operator=(const C& other) 
    {
        // 请填充
        if(this != &other) 
            return *this;
        i = other.i;
        if(data != NULL) {
            delete [] data;
        }
        data = new char[i];
        memcpy(data, other.data, i);
        return *this;
    }

    C& operator=(C&& other) 
    {
        //请填充
        if(this != &other) 
            return *this;
        i = other.i;
        if(data = NULL) 
            delete [] data;
        data = other.data;
        // memcpy(data, other.data, i);
        return *this;
    }
private:
    char* data;
    int i;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值