發表文章

第一個程式

 Hello.c 範例一:列印文字 #include <stdio.h> int main(){ printf("Hello World"); return 0; } # -> 前置處理指令 include -> 匯入 stdio.h -> 標題檔 (standard input output) int -> 整數的結果 (回傳執型態) main -> 函式名稱 (主要的) 函數、函式:Function () -> 放參數 printf -> 列印 (print format) "Hello World" -> 文字要包在雙引號內 ; -> 敘述結束符號 return -> 回傳 0 -> 結果 (0代表成功) #include <stdio.h> int main(){ printf("Hello World\n"); printf("Hello World\n"); printf("Hello World\n"); return 0; } \n -> 換行 範例二:計算長方形面積 #include <stdio.h> int main(){ int h = 100, w = 50, area = h * w; printf("長:%d,寬:%d,面積:%d\n", h, w, area); h = 200; area = h * w; printf("長:%d,寬:%d,面積:%d\n", h, w, area); return 0; } 資料:長 (h)、寬 (w)、面積 (area) -> 儲存在記憶體中 (位址) 變數 (variable) 型態:int、float、double

Ch1 變數介紹

王嘉暐 C++ 程式教學 貳、變數介紹

軟體安裝

圖片
王嘉暐 C++ 程式教學 壹、軟體安裝 一、Dev-C++ 1. 下載網址: Dev-C++ download | SourceForge.net 2. 安裝步驟: 不用選擇其他語言,選擇English即可 一直Agree,然後安裝,不用額外用任何設定,最後選擇完成 注意:記得這步驟選擇Chinese(TW),換成中文 完成後即打開介面 二、Visual Studio Code 1. 下載網址: Download Visual Studio Code - Mac, Linux, Windows 2. 事前準備:       1. 下載 mingw-w64-install          ->  網址: mingw-w64-install.exe - Google 雲端硬碟 安裝路徑請記得要設定為C:\mingw-w64(官方文件說中間不可空格) 在外掛商店裡面安裝「C++ extension for VS Code」       2. 設定 Windows 環境變數 進入控制台 在搜尋欄內輸入”進階”後找到 系統>檢視進階系統設定 選擇環境變數 找到系統變數中的PATH選擇編輯 新增C:\mingw-w64\mingw32\bin (請確認這個位置有這個資料夾)      3.   建立執行前置檔案 按下Ctrl+Shift+P,輸入edit找到Edit configurations(UI) 選擇compiler path為mingw-w64內部資料夾bin中的g++.exe 打開 launch.json -> stopAtEntry與externalConsole這項改成true 寫好程式後 -> Ctrl+Shift+B來建置檔案