①Variables, constants, and data types interpretation ②Identifier naming principle ③Sizeof usage principle ④Float scientific notation ⑤Character conversion to ASCII table ⑥Use meaning of \t [Dark horse programmer video]

【variable】
Conveniently manage memory space

【type of data】
Allocate reasonable memory space to variables

Data type variable name = variable initial value;
int a = 12;

【constant】
The amount that cannot be modified after initialization

The first type: define constants
The second type: variables defined by const

const int a = 12; 
 a = 23;   //报错

[Identifier naming principle]

  1. Cannot be a keyword
  2. Must be composed of letters, underscores, and numbers
  3. It cannot start with a number [just an underscore is also OK]
  4. Strictly control case
    Insert picture description here

[Byte judgment of data structure (sizeof)]

Use syntax:
sizeof (data structure/variable name)

short <int <= long <= long long
[long has a different number of bytes in different operating systems]

#include <iostream>
using namespace std;

int main()
{
    
    
	int num = 3;
//计算内存空间
/*  可以使用数据类型或者变量作为sizeof的内容  */

	cout << "int 型的内存空间为: " << sizeof(int) << endl;
	cout << "int 型的内存空间为: " << sizeof(num) << endl;
	return 0;
}

[Principles of using scientific notation in float]

e or E stands for 10

int main()
{
    
    
	//科学计数法
	float a1, a2;
	
	a1 = 3e2;//a1 = 3 * 10 ^ 2
	cout << "a1 = " << a1 << endl;

	a2 = 3e-2;//a2 = 3 * 0.1 ^ 2 = 3 * 10 ^ (-2)
	cout << "a2 = " << a2 << endl;
	
	return 0;
}

[Use char type to output the value of the ASCII table]

#include <iostream>
using namespace std;

int main()
{
    
    
	//错误使用:
	//error 1 :char ch = "a";    创建字符型变量时,必须用单引号
	//error 2 :char ch = 'abdffdd';   创建字符型变量时,单引号内只能是一个字符
	char ch = 'a';
	cout << (int)ch << endl;//输出97
	cout << ch << endl;//输出a

	//字符型常用
	//a--97
	//A--65
	//相差32
	return 0;
}

[Escape character--horizontal tab \t]

#include <iostream>
using namespace std;

int main()
{
    
    
	// \t 水平制表符号
	//一个\t占据8个字节空间,使用\t可以控制整齐度
	cout << "aaa\thello world!\n";
	cout << "aaaaa\thello world!" << endl;//\n等价于endl(换行字符)
	cout << "aa\thello world!\n";

	return 0;
}
//转义字符:俩个字母构成,第一个字符必为 \ ;

Escape character:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42198265/article/details/113096279