C basic syntax
We have looked at the basic structure of a C program, which will help us understand the other basic building blocks of the C language.
Tokens of C
C programs are composed of various tokens. Tokens can be keywords, identifiers, constants, string values, or a symbol. For example, the following C statement includes five tokens:
printf("Hello, World! \n");
The five tokens are:
printf("Hello, World! \n");
Semicolon;
In a C program, the semicolon Is the statement terminator. That is, each statement must end with a semicolon. It indicates the end of a logical entity.
For example, here are two different statements:
printf("Hello, World! \n");return 0;
Comments
Comments are like help text in C programs, they are ignored by the compiler. They start with /* and end with the character */, as shown below:
/* 我的第一个 C 程序 */
You cannot nest comments within comments, nor can comments appear within a string or character value.
Identifier
C Identifier is the name used to identify a variable, function, or any other user-defined item. An identifier begins with the letters A-Z or a-z or the underscore _, followed by zero or more letters, underscores, and numbers (0-9).
C Punctuation characters such as @, $, and % are not allowed within identifiers. C is a case-sensitive programming language. Therefore, in C, Manpower and manpower are two different identifiers. Several valid identifiers are listed below:
mohd zara abc move_name a_123 myname50 _temp j a23b9 retVal
Keywords
The following table lists the reserved words in C. These reserved words cannot be used as constant names, variable names, or other identifier names.
else | long | switch | |
enum | register | typedef | |
extern | return | union | |
#float | short | unsigned | |
for | signed | void | ##continue |
sizeof | volatile | default | |
static | while | do | |
struct | _Packed | ##double | |
Spaces in CLines containing only whitespace are called blank lines, may be commented, and will be completely ignored by the C compiler. In C, whitespace is used to describe whitespace, tabs, newlines, and comments. Whitespace separates parts of a statement, allowing the compiler to identify where one element in the statement (such as an int) ends and the next element begins. So, in the following statement: int age; Here, there must be at least one space character (usually a whitespace character) between int and age so that the compiler can distinguish them. On the other hand, in the following statement: fruit = apples + oranges; // 获取水果的总数 The space character between fruit and =, or = and apples is not required, but you can add some spaces if needed to enhance readability. |