Introduction to c++

1. keywords

The first one is to introduce the keywords

here is a picture for everyone

2.namespace

The second is namespace, to prevent conflicts between variables, functions, and classes in the global domain

Let's take an example

Compile-time error, because there was a problem with a redefinition

2.namespace

Usually, we define a namespace by our names, and it can be nested, the same project can be named the same, and eventually be merged.

its useage

  1. assign namespace names and operation qualifiers

    int main()
    {
    printf("%d", N1::a);
    return 0;
    }

  2. using the "using" keywords to reference a namespace

    using N1::b;
    int main()
    {
    printf("%d", b);
    return 0;
    }

  3. using "using namespace "keywords to reference, this is commonly used

    using namespace N1;
    int main()
    {
    printf("%d", b);
    return 0;
    }

3.cin & cout

Take a example

复制代码
#include<iostream>
using namespace std;

int main()
{
	cout << "Hello world!!!" << endl;
	return 0;
}

4.The differneces in header files

The difference between c and C++ header files, to distinguish c and C++,general c++files not .h

5.std

The usage convention of std: it can be used in daily life, but it is not recommended for work

because it would expose the entire standard library

6.Default parameters

There are two types. The first is full default parameters, and the second is semi-default parameters

there are four points to knowone of them is that semi-default must be given in order from right to left, and another is that default parameter can't appear simultaneously in the declaration and definition, the third is default values must be constants or local variables, the last one is that c language doesn't support

7.Function overloading

due to the allowance in C++ for declaring several functionally similar functions with the same domain, but requiring different parameter lists

8.Quote(引用)

Quote doesn't create a new variable, it just takes another alian, all share a sigle space.

This is an example

复制代码
#include<iostream>
using namespace std;
void TestRef()
{
	int a = 10;
	int& ra = a;
	cout << a << endl;
	cout << ra << endl;
}
int main()
{
	TestRef();
	return 0;
}

cited characteristic

  1. initializations must occur when defining.

  2. a variable can have multiple references.

  3. a quotation can quatity one thing

This is an example

复制代码
#include<iostream>
using namespace std;
void TestRef()
{
	const int a = 10;
	const int& b = a;
	cout << a;
	cout << b;
}
int main()
{
	TestRef();
	return 0;
}

9.Function(作用)

  1. do the parameters

  2. make a return value

10. Efficiency

The citation is the most efficient

相关推荐
(Charon)13 分钟前
【C++】定时器进阶:使用最小堆管理定时任务
c++·算法
hansang_IR24 分钟前
【题解】 [省选联考 2021 A/B 卷] 卡牌游戏
c++·算法
这个DBA有点耶1 小时前
COUNT慢不是因为用了*,是这5个原因——1000万行数据实测+执行计划深度解析
数据库·mysql·算法
贾伟康1 小时前
【口算王|01】HarmonyOS ArkTS 口算题生成实战:按年级、运算类型和难度生成可控题目
算法·harmonyos·arkts·随机生成·口算题
lzx_0021 小时前
C++11(一)
开发语言·c++·算法
529宝宝起名网1 小时前
用 Python 实现名字寓意评分算法:基于 NLP 语义分析的名字内涵深度评估
python·算法·自然语言处理
带多刺的玫瑰2 小时前
Leecode#26刷题之删除有序数组中的重复项
数据结构·算法·leetcode
小七在进步3 小时前
C++入门(2)
java·jvm·c++
en.en..3 小时前
C语言核心解析:#define与typedef本质区别
开发语言·c++·算法
码匠许师傅3 小时前
【设计模式精讲】26.策略模式(Strategy)
c++·设计模式·策略模式·uml