close


C語言中,宣告變數名稱,有規則需要遵守:
宣告變數命名的規則 :
1、開頭必須是字母(letter)或 _ 底線(underscore)。
2、其它字母必須是英文字、數字或 _ 底線符號。
3、有區分字母的大寫小寫。
4、不能使用關鍵字(keyword)。



例:
1、開頭必須是字母(letter)或 _ 底線(underscore)。
合格變數例:
int a=0;
int _a=0;

2、其它字母必須是英文字、數字或 _ 底線符號。
合格變數例:
int abc123=0;
int _a_b_c123=0;

3、有區分字母的大寫小寫。
合格變數例:
int abc123=0;
int ABC123=0;


4、不能使用關鍵字(keyword)。

錯的變數例:
int auto=0;
int break=0;

測試程式:

#include 

int main(void)
{
int abc123=0;
int _a_b_c123=0;
int ABC123=0;
int a=0;
int _a=0;
printf("Hello!\n");
return 0;
}



測試結果:





相關參考:
Wiki- C語言
內容目錄:
4.8 資料類型
4.8.1 基礎資料類型
4.8.2 結構資料類型



 






 
















其它文章

arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()