C 基礎一初始化

2021-10-17 16:05:39 字數 1567 閱讀 4706

#include #include using namespace std;

//單行 注釋

/*多行注釋*/

//常量定義

#define month 12;

#define day 31;

/*main為c++的入口函式*/

int main()

{//變數定義

char b = 'b';

int a = 10;

const int hours = 24;

const bool flags = true;

cout << "hello world " << endl;

cout << "a = " << a << endl;

cout << "b = " << b << endl;

cout << "\n";

cout << "\n";

cout << "\n";

cout << "\n";

cout << "\n";

cout << "\n";

float second = 60.0009f; // 單精度浮點

cout << "年份 ="<< day;

cout << "月份 =" << month;

cout << "小時 =" << hours;

cout << "\n";

cout << "one minute has " 《字元陣列,雙引號

string s2 = "this is not";//c++ >字元陣列,雙引號。標頭檔案標識#include cout << s1 << endl;

cout << s2 << endl;

//布林型別

bool flag = true;

bool unflag = false;

cout << flag << endl; //0

cout << unflag << endl; //1

cout << sizeof flag << endl; /*

//cin 資料輸入:從鍵盤獲取輸入

int mya = 0;

cout <<"how old are u ? " << endl;

cin >> mya;

cout << "u are " << mya<<" years old "<> talk;

cout << "u said :" << talk << endl;

cout << "\n" << endl;

cout << "\n" << endl;

cout << "\n" << endl;*/

//運算子

int a1 = 10;

int a2 = 20;

int a1_a2 = a1 + a2;

cout << a1_a2 << endl;

//遞增運算子

int a1 = 30;

a1++;

cout << a << endl;

system("pause");

return 0;

C 基礎 預設初始化

預設情況下,動態分配的物件是預設初始化的,這意味著內建型別或組合型別的物件值將是未定義的,而類型別物件將採用預設建構函式進行初始化。預設初始化 int i int pi new int 預設初始化,採用預設建構函式,內建型別無缺省構造,值不確定 string str string pstr new ...

C 基礎 初始化列表

基本寫法 class cmyclass cmyclass cmyclass int x,int y m y y m x m y 構造函式引數存在class定義的型別時,使用初始化列表會少一次構造呼叫 include using namespace std class hand class perso...

C 統一初始化語法(列表初始化)

不格 要是世上不曾存在c 14和c 17該有多好!constexpr是好東西,但是讓編譯器開發者痛不欲生 新標準庫的確好用,但改語法細節未必是明智之舉,尤其是3年一次的頻繁改動。c 帶了太多歷史包袱,我們都是為之買賬的一員。我沒那麼多精力考慮c 14 17的問題,所以本文基於c 11標準。知其所以然...