本文為 C 語言入門快速參考,涵蓋 32 個關鍵字、命名規則、註解、資料分類、基本型別、變數定義與作用域、scanf/printf 使用細節、記憶體位址觀念。
auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if while static
_。// 註解/* 註解 */(不可巢狀)| 分類 | 範例 |
|---|---|
| 整數常數 | 1, 3445 |
| 浮點常數 | 3.14, 1.2e-5 |
| 字元常數 | 'a', 'B' |
| 字串常數 | "Hello World" |
int score; // 定義 score = 100; // 賦值 int age = 20; // 定義並初始化
int age;
scanf("%d", &age);
%d 要求十進位整數輸入。&age,& 為取址運算子。scanf("%d %d", &i, &j),分隔符為空白字元。printf("%d", age);
printf("i=%d, j=%d", i, j); // 多參數
extern void printf(const char *format, ...);\0)。{ })結束。char=1, int=4, float=4, double=8(視平台)。printf("%p", &a);