03-c language keywords, identifiers, comments

Source: Internet
Author: User


One, the key word 1. What is a keyword


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



The 2> C language provides a total of 32 keywords, all of which are given special meaning 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 and 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> are all lowercase



2> displays special colors in the development tool or in the Smart Text Editing tool. By default, all keywords in the C language are shown in Xcode with a violet-brown


3. What are keywords in the main function


int, return


One, identifier 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) identifiers, literally understood, are symbols used to identify something, the purpose of which is to separate it from the other.



2) In fact, the function of the identifier is similar to the human name, in order to distinguish each person, at the time of each person's birth 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)



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



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



L cannot start with a number



L can not use keywords as identifiers



2> naming conventions (best to follow)



L try to make a meaningful name, such as a complete English word, the name can be seen by others to the role of this identifier. If you do not understand English, you can also use pinyin, try not to be like ABCDE, SFSDFSDF and other such seemingly meaningless names



L 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

Legal identifiers

Illegal identifiers

Comments

FromNo12

From#12

The # symbol cannot be used in identifiers

My_boolean

My-boolean

The "-" symbol cannot be used in identifiers, and the underscore "_" should be used instead

Obj2

2ndObj

Identifiers cannot start with numbers

MyInt

Int

"Int" is the built-in keyword

Jack_rose

Jack&rose

Symbol ' & ' cannot appear in the identifier

Gui

G.u.i

The identifier must appear inside the "." Separator

One, note 1. What is a comment


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



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, which means you can write Chinese



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


2. Single-line Comment


1) The single-line comment starts with two forward slashes, that is, starts with//, can only comment one line, from//start to the end of this line is the contents of the comment



2) anywhere you can write a comment: Outside the function, inside, behind each statement


3. Multi-line annotations


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


4. The role of annotations


1> Annotated code does not participate in compilation



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



L from the size of the. o file can be indirectly seen that the code after the comment is not compiled



2> checking the role of code



3> Troubleshooting Errors


5. Nested behavior of annotations


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


//
// 01 The first C language program. C
//
//
// Created by Sun Da on 15/5/17.
//
//

// wow ha ha // ha ha ha

// / * fsdfsdf * / // sdfsdfsd 


2) multiline annotations can nest single-line comments


//
// 01 The first C language program. C
//
//
// Created by Sun Da on 15/5/17.
//
//

/ *
 
  // Sun Da
 
  // Description: The first C language program
 
  Role: This is a main function, the entry point of a C program
 
  * / 





3) Multiline comments cannot nest multiple lines of comments


//
// 01 The first C language program. C
//
//
// Created by Sun Da on 15/5/17.
//
//

/ * Hahaha
 
  /*Hee hee hee*/

Ha ha ha * / 





4) The following wording is wrong


//
// 01 The first C language program. C
//
//
// Created by Sun Da on 15/5/17.
//
//

// / *

Hahaha

* / 
6. Importance of annotations


l want to 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)



L 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 have been in a company for more than 1 years and have written 10 tens of thousands of lines of code, but you do not 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.



03-c language 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.