Dark Horse programmer-c language basics 1: keywords, identifiers, comments, dark horse-c
------ <A href = "http://www.itheima.com" target = "blank"> Java training, Android training, iOS training,. Net training </a>, look forward to communicating with you! -------
I. Keywords
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
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
Ii. 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
Note
FromNo12
From #12
The # symbol cannot be used in the identifier.
My_Boolean
My-Boolean
The "-" symbol cannot be used in the identifier. The underscore "_" should be used instead.
Obj2
2 ndObj
The identifier cannot start with a number.
MyInt
Int
"Int" is a built-in keyword.
Jack_rose
Jack & rose
The symbol "&" cannot appear in the identifier
GUI
G.U. I
The "." separator must appear inside the identifier.
3. Notes
1. What is annotation?
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
/*
// Author: 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.
// /*
Hahaha
*/
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.