我看的是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++規定給標識符(常量、變量)命名時,有一套自己的規則:
- 標識符不能是關鍵字
- 標識符只能是有字母、數字、下劃線組成
- 第一個字符必須是字母或下劃線
- 標識符中字母區分大小寫