C language Basic syntax examples to explain _c language

Source: Internet
Author: User

C Basic Syntax

We have looked at the basic structure of the C program, which will help us understand the other basic building blocks of C language.

C's token (tokens)

C programs are made up of various tokens, which can be keywords, identifiers, constants, string values, or a symbol. For example, the following C statement includes five tokens:

printf ("Hello, world! \ n ");

These five tokens are:

printf
(
"Hello, world! \ n"
)
;

Semicolon

In the C program, the semicolon is the statement terminator. In other words, 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 a C program that is ignored by the compiler. They start with///terminate with the character/* as follows:

/* My first C program * *

You cannot set annotations inline with annotations, and comments cannot appear in strings or character values.

Identifier

A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with the letter A-Z or a-Z or underscore _ followed by 0 or more letters, underscores, and numbers (0-9).

Punctuation characters, such as @, $, and%, are not allowed within the C identifier. 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

Key words

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
Todo Int struct _packed
Double

Spaces in C

A row that contains only spaces, called blank rows, may be annotated, and the C compiler completely ignores it.

In C, spaces are used to describe whitespace characters, tabs, line breaks, and comments. A space separates the parts of a statement so that the compiler can identify where an element in the statement (such as int) ends and where the next element begins. Therefore, in the following statement:

int age;

Here, there must be at least one empty characters (usually a blank character) between int and age so that the compiler can differentiate between them. On the other hand, in the following statement:

fruit = apples + oranges; Get the total number of fruits

The space characters between fruit and =, or = and apples are not required, but to enhance readability, you can add as many spaces as you need.

The above is the C language Basic grammar explanation, the follow-up continues to supplement the related information, thanks everybody to this station support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.