主程式都有一個以上的函式(function),’main’這個函式就是一個開頭,以這個為基準,下面來介紹結構。
主體裡面有一個return 0;,主要的用意是告訴作業系統你執行完了,沒有錯誤所以回傳0,回傳1就代表執行之間有誤。
原始碼(source code) :程式碼。
大括號(open curly brace)ex: {
內建型別(built-in type) ex: int、float、char …
分號(semicolon) ex: ;
後綴(suffix) ex: .c .cpp .o
句號(period) ex: .
IDE(integrated development environment,整合式開發環境)
命令列介面(command-line interface):文字使用介面
認識輸入/輸出(IO)
iostream式最為常用的標準程式庫(standard library),包含4個物件
- cin 標準輸入(standard input)
- cout 標準輸入(standard output)
- cerr、clog 標準錯誤(standard error)
使用輸入輸出流:
結果:
角括號(angle brackets) ex: <
標頭(header)ex: #include
雙引號(double quotation marks)ex: “
操作符(manipulator): endl 換行、會把緩衝區(buffer)的資料清除,確保輸出的東西不會存在記憶體中等待輸出。
命名空間(namespace) ex: std
範疇運算子(scope operator, ::) ex: std::cout 為了知道是哪個函式庫,所以加上::。
註解(comments):單行(single line)、成對(paired)
while:
結果:
運算子(less-than-or-equal operator,,<=) ex: a>= b
複合指定運算子(compound assignment operator, +=)ex: a += b;
前綴遞增運算子(prefix increment operator, ++) ex: ++a;
後綴遞增運算子(suffix increment operator, ++) ex: a++;
前綴遞減運算子(prefix decrement operator, --) ex: --a;
後綴遞減運算子(suffix decrement operator, --) ex: a--;
for:
結果:
while(無限輸入)
結果:
if(計算連續輸入值的次數):
結果:
最後輸入一個非整數結束while迴圈。
縮排(indentation)
可讀性(readability)
類別型別(class type)
檔案重導(file redirection)
成員函式(member function) == 方法(methon)
點號運算子(dot operator, .)
呼叫運算子(call operator, ())
括號(parentheses)
參考書籍: https://www.tenlong.com.tw/products/9789865021726?list_name=srh