
c/c++基础
文章平均质量分 71
痴憨道人
这个作者很懒,什么都没留下…
展开
-
c++之default/delete
在C++中,声明自定义的类型之后,编译器会默认生成一些成员函数,这些函数被称为默认函数。其中包括(1)(默认)构造函数(2)拷贝(复制)构造函数(3)拷贝(复制)赋值运算符(4)移动构造函数(5)移动赋值运算符(6)析构函数另外,编译器还会默认生成一些操作符函数,包括(7)operator ,(8)operator &(9)operator &&(10)operator *(11)operator ->(12)operat..原创 2022-02-05 13:54:45 · 1835 阅读 · 0 评论 -
c基础题目1
下列函数指针初始化合法的有哪几个?//void (*f)();void test1(void);void test2(int i);int test3(void);void (*f1)() = test1; // OKvoid (*f2)() = &test1; // OKvoid (*f3)() = test2; // ERRORvoid (*f4)() = *test1; // OKvoid (*f5)() = test3; // ERROR...原创 2022-02-05 13:50:50 · 433 阅读 · 0 评论 -
c++ new操作符
C++当中3种new的用法 | Fantacity近在看侯捷侯老师的著作《STL源码剖析》,书中第二张开始讲到了stl中的allocator的一个简易实现,发现原来cpp中的new其实除了我们平常用的最多的new表达式(new operator)之外,还有剩下两种用法。1. new operator/delete operatornew operator,也叫new表达式,是我们在cpp中最常见的new的用法,比如:string *pStr = new string("abd")..原创 2021-11-16 17:47:09 · 5211 阅读 · 0 评论 -
c++基础3 constexpr
下列函数指针初始化合法的有哪几个?//void (*f)();void test1(void);void test2(int i);int test3(void);void (*f1)() = test1; // OKvoid (*f2)() = &test1; // OKvoid (*f3)() = test2; // ERRORvoid (*f4)() = *test1; // OKvoid (*f5)() = test3; // ERROR...原创 2021-08-21 16:24:00 · 122 阅读 · 0 评论 -
C语言基础之格式化占位符
在 printf 系列函数中,下列哪个格式化占位符有可能导致内存任意写风险 [A]A. %nB. %dC. %pD. %s使用printf修改变量的值 —— VS2008中使用%n输出遇到的问题及解决方法#include <stdio.h>int main(void){ int e; int i = 0; e = _set_printf_count_output( 1 ); printf( "%%n support was ...原创 2021-07-14 16:05:18 · 3790 阅读 · 0 评论 -
笔试题学习
解决行间距过大,换行时按shift+回车,果然行,呵呵。改成下面这样了:题目//执行下面语句:a[4];for(int i=0;i<4;++i){ if(i&1){ a[i]=1; }}//则a数组中的值为()0 1 0 1判断奇偶,奇数为1& 按位取与| 按位取或~ 按位取非^ 按位异或https://www.runoob.com/cprogramming/c-operators.html...原创 2021-04-17 18:10:41 · 618 阅读 · 0 评论 -
C++面向对象2
虚基类原创 2021-02-18 11:31:03 · 173 阅读 · 0 评论 -
C++基础1
全局对象的构造函数会在main函数之前执行。https://blog.youkuaiyun.com/x_iya/article/details/52685139https://www.cnblogs.com/lgh1992314/p/6616361.html原创 2021-02-18 11:30:23 · 328 阅读 · 1 评论 -
stl之map vector
C++中map提供的是一种键值对容器,里面的数据都是成对出现的,如下图:每一对中的第一个值称之为关键字(key),每个关键字只能在map中出现一次;第二个称之为该关键字的对应值。——————————————————————————————————————————————一. 声明//头文件#includemap<int, string> ID_Name;// 使用{}赋值是从c++11开始的,因此编译器版本过低时会报错,如visual studio 2012map<int,原创 2021-02-07 20:44:30 · 203 阅读 · 0 评论 -
C语言基础1
小端环境输出结果为value = 0x00004043typedefstructTestData_{ unsignedintdata1:2; unsignedintdata2:12; unsignedintdata3:2}TestData;intmain(void){ TestDatadata; memset(&data,0,sizeof(data)); data.data1=0x...原创 2021-02-03 17:03:48 · 1040 阅读 · 0 评论 -
STL之string
下面这个声明会(D)const std::string str1;A:、导致编译错误B、强制程序员在str1被使用前为其赋值C、由具体实现决定其行为D、将str1的内容置为空串。原创 2021-02-03 15:12:41 · 134 阅读 · 0 评论 -
C基础之static extern
//a.h// int g_count; // first// static int g_count; // second extern int g_count; // thirdvoid addCount(int);// a.cpp#include "a.h"int g_count; // third// if no this, 无法解析的外部符号int g_count// b.cpp#include "a.h"void IncrCount(void){ g_coun.原创 2021-02-03 14:51:12 · 148 阅读 · 0 评论 -
C++之emplace
最近在写一段代码的时候,突然很好奇C++11中对push_back有没有什么改进以增加效率,上网搜了一些资料,发现果然新增了emplace_back方法,比push_back的效率要高很多。首先,写了一个类用于计时,//time_interval.h#pragma once#include <iostream>#include <memory>#include <string>#ifdef GCC#include <sys/time....原创 2021-02-03 11:20:37 · 1039 阅读 · 0 评论 -
C++之namespace
错误的是namespace A{ int i = 1;}namespace B{ void a(void); void b(void); void c(void); void d(void);}void B::a(void){ using namespace A; i++;}void B::b(void){ using A::i; i++;}void B::c(void){ A::i...原创 2021-02-02 22:12:09 · 1015 阅读 · 0 评论 -
C语言基础之#define #include
/*#define h(x) g(x)#define g(x) #x#define f(x, y) x##y#define con(x, y) x##yvoid haha(){ cout << "haha" <<endl;}int main(){ int a = 0; int b = 2; int* c = NULL; //a == 0 ? b = 1 + 2 + 3 : NULL; a == ...原创 2021-01-30 15:36:47 · 1682 阅读 · 0 评论 -
C语言基础之运算符优先级
优先级 运算符 名称或含义 使用形式 结合方向 说明 1 [] 数组下标 数组名[常量表达式] 左到右 () 圆括号 (表达式)/函数名(形参表) . ...原创 2021-01-29 16:05:28 · 528 阅读 · 1 评论 -
C语言基础之const static
以下哪一个初始化操作不合法:int i = -1;const int ic = i;const int *pic = ⁣// int *const cpi = ⁣// compile error// cannot initialize a variable of type 'int *const'// with can rvalue of type 'const int *'int main(){ return 0;}...原创 2021-01-29 15:57:01 · 1199 阅读 · 1 评论 -
c++面向对象2
int init(const std::string & info){ std::cout << info << std::endl; return 0;}class A{ int m_x;public: A():m_x(init("Init A::m_x")) {init("Call A::A()");}};class A1:public A{ int m_y; int m_x;public...原创 2021-01-29 13:17:13 · 440 阅读 · 0 评论 -
重载 覆盖 隐藏
调用重载的顺序void myfunc(char a){ cout<<"myfunc char"<<endl;}//*void myfunc(int a){ cout<<"myfunc int"<<endl;} //*///*void myfunc(long a){ cout<<"myfunc long"<<endl;} //*/int main(){ unsigne原创 2021-01-29 11:34:00 · 762 阅读 · 0 评论 -
struct和class区别、三种继承及虚继承、友元类
之前只知道在C++中类和结构体的区别只有默认的防控属性(访问控制)不同,struct是public的,而class是private的。但经过上网查资料才发现,除了这个不同之外,还有很多的知识点需要掌握。下面就听我一一道来~1、首先比较一下C中的结构体和C++中的结构体区别C++中的struct是对C中的struct进行了扩充,所以增加了很多功能,主要的区别如下图所示:上面罗列了在声明时的区别,在使用的过程中也有区别:在C中使用结构体时需要加上struct,或者对结构体使用typedef..原创 2021-01-28 19:33:16 · 1922 阅读 · 0 评论 -
c基本函数
c语言获取程序时间#include <sys/time.h>#include <stdio.h>#include <unistd.h>int main(){ struct timeval tv; gettimeofday(&tv, NULL); printf("second: %ld\n", tv.tv_sec); // 秒 printf("millisecond: %ld\n", tv.tv_sec * 1000 + ...原创 2021-01-28 15:41:23 · 186 阅读 · 0 评论 -
c++面向对象1
类中调用自己的成员 虚函数。class CParent{public: CParent() {Print();}//step2 virtual ~CParent() {}public: virtual void Print() { std::cout << "1,";//step3 } void print1() {Print();}//step2};class CSon : public CParent{publ.原创 2021-01-28 14:55:45 · 1386 阅读 · 0 评论 -
stl 函数
https://blog.youkuaiyun.com/o_ohello/article/details/88636667string转化大小写#include<bits/stdc++.h>#include<string>using namespace std;int main(){ string s = "AakoOO"; transform(s.begin(), s.end(), s.begin(), ::toupper); cout<&...原创 2021-01-25 09:59:38 · 125 阅读 · 0 评论 -
数组 指针
//以下代码输出12、//行4列#include <iostream>int main(){double alpha[][4] = { {0}, {1,2}, {3,4,5} };std::cout << sizeof(alpha) / sizeof(double);return 0;}原创 2021-01-22 14:10:12 · 738 阅读 · 0 评论 -
std::copy std::move
https://www.cnblogs.com/xuhuajie/p/11491924.htmlvoid fun(int T)void fun(int* t)oid fun(int& T)void fun(int && T)之前的参数,值传递,指针传递,引用传递。现在呢?多了一个叫 “右值引用”的玩意,多了一种参数类型的选择。仅此而已。那他们号称的右值引用速度快,代价小呢?https://blog.youkuaiyun.com/HelloZE...原创 2021-01-22 11:23:40 · 1181 阅读 · 0 评论 -
大端小端 内存对齐 内存四(五)区
大端小端原创 2021-01-16 11:26:05 · 426 阅读 · 0 评论