Cprogramming 简明教程
Special Characters in C
C 语言识别一个包含英语字母(大写和小写(A 到 Z 以及 "a" 到 "z")、数字 0 到 9 和某些称为“特殊字符”且带有特定含义的其他符号的字符集。
The C language identifies a character set that comprises English alphabets – upper and lowercase (A to Z as well as "a" to "z"), digits 0 to 9, and certain other symbols called "special characters" with a certain meaning attached to them.
虽然特殊符号类别中的许多字符被定义为运算符,但某些字符组合也具有特殊的含义。例如, "\n" 称为 newline character. 此类组合称为 escape sequences 。
While many of the characters in the special symbol category are defined as operators, certain combinations of characters also have a special meaning attached to them. For example, "\n" is known as the newline character. Such combinations are called escape sequences.
在 C 语言中,引号也具有特殊的含义。双引号用于字符串,而字符用单引号括起来。阅读此章节以详细了解在 C 程序中使用的其他特殊字符。
In C language, quotation marks too have a special meaning. Double quotes are used for strings, while characters are enclosed inside single quotes. Read this chapter to learn more about the other special characters used in C programs.
Parentheses ()
括号特别用于对表达式中一个或多个运算数进行分组,并控制语句中的运算顺序。
Parentheses are especially used to group one or more operands in an expression and control the order of operations in a statement.
括号内嵌入了部分表达式,其优先级更高。
A part of the expression embedded inside parentheses has a higher order of precedence.
Braces { }
大括号特别用于定义代码块,例如 function 正文和 loops 。它们还用于初始化 arrays 和 struct variables 。
Braces are especially used to define blocks of code, such as function bodies and loops. They are also used to initialize arrays and struct variables.
Examples
大括号在函数定义中 -
Braces in function definition −
int add(int a, int b){
int sum = a + b;
return sum;
}
大括号在数组初始化中 -
Braces in array initialization −
int arr[5] = {1, 2, 3, 4, 5};
大括号在结构变量中 -
Braces in struct variable −
struct book {
char title[10];
double price;
int pages;
};
struct book b1;
struct book b1 = {"Learn C", 675.50, 325};
Square Brackets [ ]
方括号用于声明数组和使用下标索引访问数组元素。
Square brackets are used to declare arrays and access elements of an array with the subscript index.
Asterisk (*)
除了将其用作乘法运算符之外,星号 (*) 符号还用于声明 pointer variable 并 dereference 它以获得目标变量的值。
Apart from its use as a multiplication operator, the asterisk symbol (*) is also used to declare a pointer variable and dereference it to obtain the value of the target variable.
Ampersand (&)
"&" 符号用作 address-of operator 。它返回变量的地址。
The ampersand (&) symbol is used as the address-of operator. It returns the address of a variable.
Comma (,)
逗号用作语句或函数调用之间的分隔符。
The comma is used as a separator between a statement or a function call.
Semicolon (;)
作为 C 中的一个主要语法规则,分号指明 C program 中语句的结束。
As a primary syntax rule in C, the semicolon indicates the end of a statement in a C program.
Dot (.)
dot symbol (.) 用于访问结构或 union 的成员。
The dot symbol (.) is used to access the members of a structure or a union.