随笔分类 - C++基础知识点部分
摘要:注意: 加入const之后,一旦有修改的操作就会报错,可以防止我们的误操作
阅读全文
摘要:注意: 如果不想修改主函数中的数据,用值传递,反之用地址传递 点击查看代码 #include<iostream> #include<string> using namespace std; struct student { //成员列表 string name; int age; int score
阅读全文
摘要:注意: 在结构体中可以定义另一个结构体作为成员,用来解决实际问题 先定义 子结构体,后定义 父结构体 点击查看代码 #include<iostream> #include<string> using namespace std; //先定义 子 结构体 struct student { //成员列表
阅读全文
摘要:结构体数组 点击查看代码 #include<iostream> #include<string> using namespace std; //结构体数组 //1、定义结构体 struct Student { //成员列表 string name; int age; int score; }; in
阅读全文
摘要:点击查看代码 #include<iostream> #include<string> using namespace std; //创建一个 自定义的数据类型 //语法:struct 类型名称 { 成员列表 }; struct Student { //成员列表 string name; int ag
阅读全文
摘要:点击查看代码 #include<iostream> #include<string> using namespace std; int main(){ int arr[10] = { 1,2,3,4,5,6,7,8,9,10 }; cout << "第一个元素arr[0]是:" << arr[0]
阅读全文
摘要:技巧:看const右侧紧跟着的是指针还是常量,是指针就是常量指针,是常量就是指针常量。 const修饰指针 —— 常量指针 点击查看代码 #include<iostream> #include<string> using namespace std; int main(){ int a = 10;
阅读全文
摘要:注意:指针也是一种数据类型 将16进制的数,强转成一个地址,前面加(int *) 总结:空指针和野指针都不是我们申请的空间,因此不要访问。
阅读全文
摘要:点击查看代码 #include<iostream> #include<string> using namespace std; //函数的声明 //比较函数,实现两个整型数字进行比较,返回较大的值 //提前告诉编译器函数的存在,可以利用函数的 声明 //函数声明可以写多次,但是定义只能有一次 int
阅读全文
摘要:函数定义的时候,num1 和 num2 并没有真是数据,他只是一个形式上的参数,简称 形参 a 和 b 称为实际参数,简称 实参 当调用函数时候,实参 的值会 传递 给形参 值传递 见C++不完全学习笔记
阅读全文
摘要:外层循环打印行数,内层循环打印列数 点击查看代码 #include<iostream> #include<string> using namespace std; int main() { //2. 数据类型数组名[ 行数 ][ 列数 ] = { {数据1,数据2 },{数据3,数据4 } }; i
阅读全文
摘要:数组特点:(1)我们可以通过 下标 访问数组中的元素(2)放在一块连续的内存空间中(3)数组中每个元素都是相同数据类型 (1) n = sizeof(数组名) / sizeof(数组名[i]) ; (2) cout << arr << endl; (3) cout << "数组首地址为:" << (
阅读全文
摘要:三目运算符计算结果返回的是一个变量; 计算结果可以放在等号右侧,给等号左侧赋值;也可以放在等号左侧,返回一个变量,继续后续运算 在C++中三目运算符返回的是变量,可以继续赋值 跳转语句 break 出现在switch条件语句中,作用是终止case并跳出switch 出现在循环语句中 出现在嵌套循环中
阅读全文
摘要:总结:前置递增先对变量进行++,再计算表达式,后置递增相反
阅读全文
摘要:点击查看代码 #include<iostream> #include<string> using namespace std; int main() { //整型 int a = 0; cout << "给整型变量a赋值:" << endl; cin >> a; cout << "a = " <<
阅读全文
摘要:字符串类型 点击查看代码 int main() { //1、C风格字符串 //注意事项 // char 字符串名 [ ] // 等号后面要用 双引号包含起来字符串 char str[] = "hello"; cout << str << endl; cout << sizeof(str) << en
阅读全文
摘要:sizeof关键字 实型 有效数字包括小数点以前的数字 float num1 = 3.14 f ; 默认情况下输出一个小数,小数点后最多显示6位有效数字 转义字符 点击查看代码 #include<iostream> #include<string> using namespace std; //转义
阅读全文

浙公网安备 33010602011771号