C語言基本語法

C語言基本語法 實例代碼教程- 我們已經看到的C程序的基本結構,所以這將是很容易理解其他的C語言編程的基本構建塊。

你已經看到的C程序的基本結構,所以這將是很容易理解其他的C語言編程的基本構建塊。

C語言的記號

C程序由各種令牌,令牌可以是關鍵字,標識符,常量,字符串文字或符號。例如,下面的C語句包含五個令牌:

printf("Hello, World! \n");

The individual tokens are:

printf
(
"Hello, World! \n"
)
;

分號 ;

In C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.

For example, following are two different statements:

printf("Hello, World! \n");
return 0;

註釋

Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminates with the characters */ as shown below:

/* my first program in C */

You can not have comments with in comments and they do not occur within a string or character literals.

標識符

C標識符是用來標識變量,函數的名稱,或任何其它用戶定義的項目。開始的標識符以字母A到Z或az或下劃線_由零個或多個字母,下劃線和數字(09)。

C does not allow punctuation characters such as @, $, and % within identifiers. C is a case sensitiveprogramming language. Thus Manpower and manpower are two different identifiers in C. Here are some examples of acceptable identifiers:

mohd       zara    abc   move_name  a_123
myname50   _temp   j     a23b9      retVal

關鍵字

The following list shows the reserved words in C. These reserved words may not be used as constant or variable or any other identifier names.

autoelselongswitch
breakenumregistertypedef
caseexternreturnunion
charfloatshortunsigned
constforsignedvoid
continuegotosizeofvolatile
defaultifstaticwhile
dointstruct_Packed
double


C語言中的空白行

A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it.

Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement:

int age;

必須有至少一個空白字符(通常是int和年齡的編譯器能夠區分它們之間有一個空格)。另一方面,在下面的語句

fruit = apples + oranges;   // get the total fruit

任何空白字符是必要的之間水果和=,=蘋果,雖然你是自由的,包括一些,如果你想可讀性目的。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章