我看的是B站黑马程序员的课《C++教程》。准备用这个专栏记录一下学习笔记。
这套c++课程的课程安排如下:
阶段 | 内容 | 目标 | 案例 |
第一阶段 | C++基础语法入门 | 对c++有初步了解,能够有基础编程能力 | 通讯录管理系统 |
第二阶段 | c++核心编程 | 介绍c++面向对象编程,为大型项目做铺垫 | 职工管理系统 |
第三阶段 | c++提高编程 | 介绍c++泛型编程思想,以及STL的基本使用 | 演讲比赛系统 |
目录
一、第一个c++程序
二、程序的注释
1、单行注释://
2、多行注释:/**/
三、变量
四、常量
五、关键字
六、标识符命名规则
一、第一个c++程序
#include <iostream>
using namespace std;int main()
{cout << "hello world" << endl;system("pause");return 0;
}
二、程序的注释
1、单行注释://
2、多行注释:/**/
三、变量
作用:给一段指定的内存空间起名,方便操作这段内存
语法:数据类型 变量名 = 初始值;
实例:
#include <iostream>
using namespace std;int main()
{int a = 10;cout << "a = " << a << endl;system("pause");return 0;
}
四、常量
作用:用于记录程序中不可更改的数据
方式:
1、#define 宏常量: #define 常量名 常量值
通常在文件上方定义,表示一个常量。
2、const修饰的变量:const 数据类型 常量名 = 常量值;
通常在变量定义前加关键字const,修饰该变量为常量,不可修改。
示例:
#include <iostream>
using namespace std;#define Day 7int main()
{const int month = 12;cout << "一周总共有" << Day << "天" << endl;cout << "一年总共有" << month << "个月" << endl;system("pause");return 0;
}
五、关键字
作用:在c++中预先保留的单词(标识符),不能用于定义常量和变量
c++关键字如下:
asm | do | if | return | typedef |
auto | double | inline | short | typeld |
bool | dynamic_cast | int | signed | typename |
break | else | long | sizeof | union |
case | enum | mutable | static | unsigned |
catch | explicit | namespace | static_cast | using |
char | export | new | struct | virtual |
class | extern | operator | switch | void |
const | false | private | template | volatile |
const_cast | float | protected | this | wchar_t |
continue | for | public | throw | while |
default | friend | register | true | |
delete | goto | reinterpret_cast | try |
六、标识符命名规则
作用:c++规定给标识符(常量、变量)命名时,有一套自己的规则:
- 标识符不能是关键字
- 标识符只能是有字母、数字、下划线组成
- 第一个字符必须是字母或下划线
- 标识符中字母区分大小写