C++ Primer 5th笔记(2)chapter 2变量和基本类型:变量声明、关键字
生活随笔
收集整理的這篇文章主要介紹了
C++ Primer 5th笔记(2)chapter 2变量和基本类型:变量声明、关键字
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
0. 幾個零星知識點
. 嵌套作用域:局部變量會覆蓋全局變量
. char 在有些機器有符號,有的無符號。
. 標識符大小寫敏感。
1.變量聲明和定義
c++ 將聲明和定義分開來。
聲明 extern int i;// 指定變量名字、類型
定義 extern double pi = 3.45; //申請存儲空間、為變量賦初值
變量可以聲明多次,定義一次.
eg.
shareVariable.h
#ifndef SHAREVARIABLE_H #define SHAREVARIABLE_Hextern int nShare;// 指定變量名字、類型#endifuseShareVariable1.h
#ifndef USESHAREVARIABLE1_H #define USESHAREVARIABLE1_H#include <iostream>#include "shareVariable.h"extern int nShare = 1;// 定義變量class useShareVariable1 { public:void static test() {std::cout << nShare;} }; #endifuseShareVariable2.h
#ifndef USESHAREVARIABLE2_H #define USESHAREVARIABLE2_H#include <iostream>#include "shareVariable.h"extern int nShare;//聲明變量,該句也可以忽略class useShareVariable2 { public:void static test() {std::cout << nShare;} }; #endif2. c++關鍵字
我不認識的:decltype
asm
constexpr
const_cast
mutable
noexcept
thread_local
static_cast
staitic_assert
reinterpret_cast
volatile
3. c++操作符替代名
參考
[1]: 代碼 https://github.com/thefistlei/cplusprimer/tree/main/cprimer
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的C++ Primer 5th笔记(2)chapter 2变量和基本类型:变量声明、关键字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++ Primer 5th笔记(2)c
- 下一篇: C++ Primer 5th笔记(2)c