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

任何空白字符是必要的之间水果和=,=苹果,虽然你是自由的,包括一些,若是你想可读性目的。

相关文章
相关标签/搜索