May 11, 2021 C
We've seen the basic structure of the C program, which will help us understand the other basic building blocks of the C language.
The C program consists of a variety of tokens, which can be keywords, identifiers, constants, string values, or a symbol. For example, the following C statement includes five tokens:
printf("Hello, W3Cschool! \n");
The five tokens are:
printf // 标识符
( // 符号
"Hello, W3Cschool! \n" // 字符串值
) // 符号
; // 分号是语句结束符
In a C program, a sign is the statement end character. T hat is, each statement must end with a sign. It indicates the end of a logical entity.
For example, here are two different statements:
printf("Hello, W3Cschool! \n");
return 0;
Comments are like help text in a C program, and they are ignored by the compiler.
They start
/*
end with the
*/
as follows:
// 单行注释
/*
多行注释
多行注释
多行注释
*/
//
known as line-level comments because only one line can be commented
/* */
comment, also known as a quick-level comment, and a comment in this format can be one or more lines.
Error demo:
//我是单行注释//的错误演示
char a ='//A';
The C identifier is the name used to identify a variable, function, or any other user-defined item.
An identifier starts with
A-Z
or
a-z
or underscore, followed by zero or more letters, underscores, and
0-9
_
Punctuation characters, such as , $, and %,
@
$
C
%
C
is
a case-sensitive
programming language. T
herefore, in C,
Manpower
and
manpower
are two different identifiers.
Here are a few valid identifiers:
mohd zara abc move_name a_123
myname50 _temp j a23b9 retVal
The following table lists the reserved words in C. These reserved words cannot be used as constant names, variable names, or 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 |
A line that contains only spaces, called a blank line, may be annotated and ignored entirely by the C compiler.
In C, spaces are used to describe blanks, tabs, line breaks, and comments. S
paces separate parts of a statement, allowing the compiler to identify where
int
ends and where the next element begins.
Therefore, in the following statement:
int age;
Here, there must be
age
one space character (usually a blank character) between
int
and age so that the compiler can distinguish them.
On the other hand, in the following statement:
fruit = apples + oranges; // 获取水果的总数
fruit
=
fruit and ,
apples
are not required, but for greater readability, you can add some spaces as needed.
=