編譯期運算符,非函數。sizeof(int) 需括號,sizeof x 變量可無括號。
const int *p (值不可變)、int *const p (指針不可變)、const int *const p (雙不可變)。const int i 防止誤改。聲明外部符號定義在別處,跨文件共享變量/函數。
struct 成員默認 public,class 默認 private;空結構體大小為 1 字節。
成員共享內存,大小等於最大成員;同一時刻只存一個值。
類型別名,簡化聲明(如 typedef int (*PF)(int,int);)。
條件編譯,構建編譯選擇階梯。
原樣替換,務必加括號:
[cpp]
#define SQR(x) ((x)*(x)) // 正確
#define SQR(x) x*x // 錯誤:SQR(1+1) → 1+1*1+1 = 3
a == &a[0])。a = p 錯誤。&a 是數組指針(int (*)[N]),&a+1 跨越整個數組。
// file1.c
char a[100];
// file2.c
extern char *a; // 錯誤!應為 extern char a[]; 或 extern char a[100];
數組與指針本質不同:數組即內存塊,指針存地址;混用導致訪問錯誤地址。
一維數組參數總是退化為指針:void f(int a[]) ≡ void f(int *a);二維數組保留第二維:void f(int a[][N])。