C語言基本語法

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

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

C語言的記號

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

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.ui

For example, following are two different statements:spa

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:orm

/* 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)。token

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:ci

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.

auto else long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _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

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

相關文章
相關標籤/搜索