第一個程式
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
留言
張貼留言