C Language Introduction: 03. Keywords, identifiers, comments

Source: Internet
Author: User

first, the warning before learning grammar

(1) C language belongs to a high-level language, in fact, all the basic grammatical components of high-level languages are the same, but the form is not the same

(2) Like Asians and Africans, we all have a human structure: 2 hands, 2 feet, 1 heads, but they don't look the same, like skin color, face shape.

(3) Therefore, you have mastered a high-level language, and then to learn other high-level language, it is quite fast

(4) Moreover, many other high-level languages, such as the back to learn objective-c, are based on C language, derived from C language, learn C language Well, absolutely not suffer

second, the key word

1. What is a keyword

(1) The keyword is the C language provides a special meaning of the symbol, also known as "reserved word"

(2) The C language provides a total of 32 keywords, all of which are given special meaning by C language

AutoDoubleIntstructBreakElselong switchcase enum register typedef char extern return Unionconst  float short unsigned continue for signed voiddefault goto sizeof volatile Span style= "color: #0000ff;" >do if while static  

Roughly browse once again, do not have to Baidu each keyword role, these keywords will often use later, when you want not to remember is difficult

2. Characteristics of keywords

(1) All lowercase

(2) Special colors are displayed in the development tool or the Smart Text Editing tool. By default, all keywords in the C language are shown in Xcode with a violet-brown

Which of the 3.main functions are keywords

int,return
Third, identifiers

1. What is an identifier

Identifiers are some of the symbols and names that you customize in your program. To differentiate from keywords: the keyword is the symbol that is provided by the C language by default, and the identifier is a programmer-defined

2. The role of identifiers

(1) An identifier, literally understood, is a symbol used to identify something, the purpose of which is to separate it.

(2) In fact, the function of the identifier is similar to the name of the human, in order to distinguish each person, in the birth of each person has a name

(3) C language is composed of functions, a C program may have more than one function, in order to distinguish these functions, each function is given a name. The name of the function is one of the identifiers. In addition to the function, the concept of "variable" will be learned later, and the name of the variable is also the identifier

3. Naming

(1) Naming rules (be sure to follow)

Can only be made up of 26 letters in uppercase and lowercase, 10 Arabic numerals 0~9, underline _

Strictly case-sensitive, such as test and test are 2 different identifiers

Cannot start with a number

You cannot use a keyword as an identifier

(2) naming specification (best to follow)

Try to make a meaningful name, such as a complete English word, which can be useful if someone sees the name. If you do not understand English, you can also use pinyin, try not to be like ABCDE, SFSDFSDF and other such seemingly meaningless names

If the identifier contains more than one word, you can use the Hump logo (except for the first word, the first letter of each word is capitalized): FirstName, MyFirstName, or use the underscore _ to connect: first_name, My_first_name

4. Common identifier naming errors

5. Exercises

Indicate the correctness of identifiers

Test1      mike2jack    my_text  _testtest!32   haha (DA) TT   haha _text  123haha78text    a      _123    _
Iv. Notes

1. What is a comment

(1) Annotations are a concept that is very important in all computer languages, literally, the meaning of annotations and interpretations.

(2) Comments can be used to explain the meaning of a program or a line of code to facilitate communication between programmers. If I finish writing a line of code and add the corresponding comment, then people will see this comment and know what my line of code is for.

(3) Comments can be any text, that is, you can write Chinese

(4) Note in development tools is generally red bean paste Green

2. Single-line Comment

(1) A single-line comment begins with two forward slashes, that is, starting with//, only one line is commented, from//To the end of the line is the contents of the comment

(2) Any place can write comments: Outside the function, inside, after each statement

3. Multi-line annotations

Multiline comments start with/*, end with */, the contents of/* and/* are commented

4. The role of annotations

(1) The annotated code will not participate in the compilation

A note is written to people, not to a computer. How can a computer see the Chinese we write? Therefore, when compiling the program, the comments are not compiled into the. O Destination file

From the size of the. o file, you can see indirectly that the code after the comment has not been compiled

(2) Check the function of the code

(3) Troubleshooting errors

5. Nested behavior of annotations

(1) Single-line comments can be nested single-line comments, multiline comments

 // ah ha//// / sdfsdfsd    

(2) Multiline annotations can nest single-line comments

/*   //MJ//Description: First C language Program function: This is a main function, the C program's entry point  * /

(3) Multiline annotations cannot nest multiple lines of comments

  /* ha ha  * * * giggle Hee * * *    ~ ~  

(4) The following wording is wrong

/ *  ha haha * 

6. Importance of annotations

Develop a good habit of writing notes. Most project managers check the subordinate code of the first thing is to see if there is no comment, there are many companies will also check the machine test comments (the test is to give you a programming problem, a computer, in the specified time to solve problems)
Today, you wrote hundreds of lines of code, very happy, made a very nice feature, but forgot to write the comments. After one weeks, it's normal for you to go back and look at that piece of code, which you may not be able to understand at all. If you write a comment, the situation is different, and comments can help you review the role of the Code.
You've been in a company for over 1 years, and you've written 10, tens of thousands of lines of code, but you don't write a note. One day you quit and the new employee takes over your project, the first thing he must do is to read the code you wrote. But you did not write a little note, 100,000 lines of code, all in English, which will make the new employee very egg pain. Everyone has their own ideas, the idea of writing code is certainly not the same, it is very painful to see the code written by others, especially the code without comments. The way you do not write comments can greatly reduce your company's development efficiency. As a result, all formal companies attach great importance to annotations.

7. Exercises

See if the following programs can run successfully, and if so, say the results of the operation:

(1) Procedure 1

main function int main () {    printf ("itcast\n"0;}       

(2) Procedure 2

main function int main ()  {    printf ("//itcast\n"0;}     

(3) Procedure 3

Main function int main ()  {    printf ("itcast\n"0;}      

(4) Procedure 4

int Main () {    printf (//"itcast\n");    0;}    

(5) Procedure 5

main function {    //printf ("itcast\n");    0;}    

C Language Introduction: 03. Keywords, identifiers, comments

Related Article

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.