04-keywords, identifiers, and comments

Source: Internet
Author: User
I. Reminders before learning the syntax

1) C language is a high-level language. In fact, the basic syntax components of all advanced languages are the same, but the expressions are not the same.

2) Just like the Asian and African people, everyone has a human structure: two hands, two feet, and one head, but they have different appearances, such as skin color and face shape.

3) Therefore, you have mastered a high-level language and want to learn other advanced languages, which is quite fast.

4) In addition, many other advanced languages, such as objective-C to be learned later, are derived from C language and are derived from C language. Study C language well and never suffer losses.


Ii. Keyword 1. What is a keyword?

1> keywords are symbols with special meanings provided by the C language, also known as "Reserved Words"

2> A total of 32 keywords are provided in C language. These keywords are given special meanings by C language.

Auto double int struct break else long switch

Case Enum register typedef char extern return Union

Const float short unsigned continue for signed void

Default goto sizeof volatile do if while static

You can simply browse it over again without having to go to the functions of every keyword of Baidu. These keywords will be frequently used in the future, and it will be hard for you to remember them.

2. Keyword features

1> all are in lower case

2> special colors are displayed in development tools or smart text editing tools. By default, all keywords in the C language are purple-brown in xcode.

3. What are keywords in the main function?

Int, return


Iii. identifier 1. What is an identifier

Identifiers are some of the symbols and names customized in the program. To distinguish it from keywords: keywords are the symbols provided by C language by default, and identifiers are customized by programmers.


2. Functions of identifiers

1) identifiers. Literally, They are symbols used to identify something. They are used to distinguish them.

2) In fact, the role of an identifier is similar to that of a human name. To distinguish each person, a name is given at the time of birth.

3) C language is composed of functions. a c program may have multiple functions. to distinguish these functions, each function is named. The function name is a type of identifier. In addition to functions, we will also learn the concept of "variables". The variable name is also an identifier.


3. Name

1> naming rules (must comply)

L can only contain 26 English letters, 10 Arabic numerals, 0 ~ 9. Underline _

L strictly case sensitive. For example, test and test are two different identifiers.

L cannot start with a number

L you cannot use keywords as identifiers.


2> naming conventions (preferably observed)

L try to create a meaningful name, such as a complete English word. Only when someone else looks at the name can this identifier be used. If you do not understand English, you can also use Pinyin. Try not to use meaningless names such as ABCDE and sfsdfsdf.

L if the identifier contains multiple words, you can use the camper mark (except for the first word, the first letter of each word is capitalized): firstname, myfirstname, or use underscore _ to connect: first_name, my_first_name


4. common identifier naming errors

Legal identifier

Invalid identifier



From #12

The # symbol cannot be used in the identifier.



The "-" symbol cannot be used in the identifier. The underscore "_" should be used instead.


2 ndobj

The identifier cannot start with a number.



"Int" is a built-in keyword.


Jack & Rose

The symbol "&" cannot appear in the identifier


G.u. I

The "." separator must appear inside the identifier.


5. Exercise

Identifies correctness

Test1 mike2jack my_text _ Test

Test! 32 Haha (DA) TT Haha _ text 123 haha

78 text A _ 123 _


Iv. Comment 1. What is comment

1) annotation is a very important concept in all computer languages. Literally, it refers to the meaning of annotation and interpretation.

2) annotations can be used to explain the meaning of a program or a line of code to facilitate communication between programmers. If I add the corresponding comments after writing a line of code, then when someone else sees this comment, they will know what the code is.

3) Comments can be any text, that is, Chinese characters can be written.

4) in development tools, the comment is generally bean paste green


2. Single Row comment

1) A single line comment starts with two forward slashes, and starts with //. Only one line can be commented. From // to the end of this line, all comments are comments.

2) Comments can be written anywhere: Outside the function, inside it, after each statement


3. Multi-line comment

Multi-line comments start with/* and end with */. The content in the middle of/* and */is both comments.


4. Functions of annotations

1> the annotated code does not participate in compilation.

L annotations are written to people, not to computers. How Can computers view the Chinese we write. Therefore, when the program is compiled, the comments are not compiled into the. O target file.

L from the size of the. o file, we can indirectly see that the annotated code is not compiled.

2> check the function of the Code

3> troubleshooting


5. annotation nesting

1) single-row comments can be nested with single-row comments and multi-row comments

// Wow Haha // hehahaha

/// * Fsdfsdf * // sdfsdfsd

2) multi-line comments can be nested with single-line comments


// Mj

// Description: The first C Language Program

Role: This is a main function, the entry point of the C program


3) multi-line comments cannot be nested with multi-line comments

/* Hahaha

/* Xi */

Haha */

4) The following statements are incorrect.





6. Importance of annotations

L develop a good habit of writing comments. The first thing for most project managers to check their subordinate codes is to see if they have written comments. Many companies also try to check comments. (A computer test is to give you a programming question and a computer, solve the problem within the specified time)

L today, you have written several hundred lines of code. I'm glad that you have made a very good function. However, you forgot to write comments. After a week, you may not be able to understand the code. This is a normal task. If you write comments, the situation will be different. Comments can help you review the role of the Code.

L you have been in a company for more than one year and have written tens of thousands of lines of code, but you do not need to write any comments. One day, when you leave your job and a new employee takes over your project, he must first understand the code you wrote. However, you did not write any comments at all. The 0.1 million lines of code are all in English, which makes this new employee very painful. Everyone has their own ideas. The idea of writing code is definitely different. It is very painful to read the code written by others, especially the code without comments. If you do not write comments, the company's development efficiency will be greatly reduced. Therefore, all formal companies place great importance on annotations.


7. Exercise

Check whether the following program runs successfully. If yes, the running result is displayed:

1> program 1

// Main Function

Int main (){

Printf ("itcast \ n ");

Return 0;


2> Procedure 2

// Main Function

Int main (){

Printf ("// itcast \ n ");

Return 0;


3> Program 3

Main Function

Int main (){

Printf ("itcast \ n ");

Return 0;


4> Procedure 4

Int main ()


Printf (// "itcast \ n ");

Return 0;


5> program 5

Int main () // main function {

// Printf ("itcast \ n ");

Return 0;


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.