![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
面试
fzzjoy
Code Change World
展开
-
【面试题】手撸shared_ptr的实现
简单实现了一个线程不安全的版本:#include <iostream>using namespace std;int new_cnt = 0;int del_cnt = 0;template <class T>class Sptr{public: // 默认构造和析构函数 Sptr(T *ptr = nullptr) // 此时编译器不会生成默认的构造函数 无论有没有默认的实参 : data_(ptr) , ref原创 2021-09-04 15:11:51 · 268 阅读 · 0 评论 -
【面试题】将字符串中的所有空格去掉,要求时间复杂度O(n),空间复杂度O(1)
//题目:将字符串中的所有空格去掉,要求时间复杂度O(n),空间复杂度O(1)#include <iostream>#include <string.h>#include <assert.h>using namespace std;int delSpace(char *pStr){ assert(pStr); char *...原创 2018-04-06 21:35:15 · 2472 阅读 · 0 评论 -
【面试题】String类型中间可以包含'\0'吗
答案是可以的,Test:#include #include using namespace std;int main(){ char *cStr = "hello\0world"; string str{'a', 'b', '\0', 'c'}; string str1("world\0hello"); unsigned char b = 255;原创 2018-04-07 15:35:49 · 7834 阅读 · 1 评论 -
【面试题】共用体(联合体)简介及在大小端判断的巧妙运用
共用体union:几个不同类型的变量共享同一段内存的结构,称为共用体(定义是核心)。共用体的定义、声明均与结构体一样,定义共用体类型一般形式为:union 共用体名{成员列表;}变量列表;例如:union Data{ //表示不同类型的变量i、ch、f可以存放到同一段存储单元中。short i; char ch;float f;}a,b,c; /...原创 2015-10-31 13:17:05 · 5195 阅读 · 0 评论