C Language Section III keywords, identifiers, comments

Source: Internet
Author: User

    1. A reminder before you learn grammar
    • 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
    • It's like Asians and Africans, everyone has a human structure: 2 hands, 2 feet, 1 heads, but they look different, such as skin color, face shape
    • Therefore, you have mastered a high-level language, and then to learn other high-level language, it is quite fast
    • Moreover, many other high-level languages, such as the objective-c to learn, are based on C language, derived from C language, learn C language Well, absolutely not suffer

?

    1. Key words
    1. What is a keyword
    2. Keyword is the C language provides a special meaning of the symbol, also known as "reserved word"
    3. The C language provides a total of 32 keywords, all of which are given special meaning by C language

auto Doubleint structbreak else Longswitch

case Enumregister typedefchar extern Returnunion

const Floatshort unsignedcontinueforsignedvoid

Defaultgotosizeofvolatiledoifandstatic

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

    1. Characteristics of keywords
    2. All of them are lowercase.
    3. Special colors are displayed 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
    4. Which of the main functions are keywords

int,return

?

    1. 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

?

    1. The role of identifiers
    • An identifier, literally understood, is a symbol used to identify something, the purpose of which is to separate it.
    • 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
    • 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

?

    1. Named
    2. 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

?

    1. Naming conventions (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

?

    1. Common identifiers are named incorrectly

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

?

    1. Exercises

Indicate the correctness of identifiers

Test1 Mike2jack My_text _test

test!32 haha (DA) TT haha _text 123haha

78text a _123 _

?

    1. Comments
    1. What is a comment
    • Annotations are a very important concept in all computer languages, literally, the meaning of annotations and explanations.
    • Annotations can be used to explain what a piece of program or a line of code means, facilitating 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.
    • Comments can be any text, meaning you can write Chinese
    • Notes in development tools are generally red bean paste Green

?

    1. Single-line Comment
    • A single-line comment starts with two forward slashes, that is, starts with // , can only comment on one line, from // start to the end of the line is the contents of the comment
    • You can write notes anywhere: Outside the function, inside, behind each statement

?

    1. Multi-line comments

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

?

    1. The role of annotations
    2. The commented 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
    1. Check the role of the Code
    2. Troubleshoot errors

?

    1. Nested behavior of annotations
      1. Single-line comments can nest single -line comments, multiline comments

// Wow, haha . // Oh, huh ?

// /* fsdfsdf */  // sdfsdfsd

    1. Multiline comments can nest single-line comments

/*

// MJ 

// 描述:第一个C语言程序

作用:这是一个主函数,C程序的入口点

*/

    1. Multi-line annotations cannot nest multiple lines of comments

/* 哈哈哈

  /*嘻嘻嘻*/

   呵呵呵 */

    1. The following wording is wrong .

// /*

哈哈哈

*/

?

    1. Importance of annotations
    • 要养成写注释的良好习惯。绝大部分项目经理检查下属代码的第一件事就是看有没有写注释,也有很多公司的机试也会检查注释(机试就是给你一道编程题、一台电脑,在规定时间内解题)
    • 今天,你写了几百行代码,很高兴,做出了一个非常不错的功能,但是,忘了写注释。一个星期过后,你再回去看那一段代码,你可能完全看不懂了,这是很正常的事。如果你写了注释,那情况就不一样了,注释可以帮助你回顾代码的作用。
    • 你在某家公司待了1年多,写了10几万行代码,但是你不写一点注释。有一天你离职了,新的员工接手你做的项目,他首先要做的事情肯定是要读懂你写 的代码。可是你一点注释都没写,10万行代码,全部都是英文,这会让这位新员工非常地蛋疼。每个人都有自己的思想,写代码的思路肯定是不一样的,看别人写 的代码是件非常痛苦的事情,特别是没有注释的代码。你不写注释的做法会大大降低公司的开发效率。因此,所有的正规公司都非常重视注释。

?

    1. 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");

return 0;

}

    1. Procedure 2

// Main function

int main () {

printf ("//itcast\n");

return 0;

}

    1. Procedure 3

Main function

int main () {

printf ("itcast\n");

return 0;

}

    1. Procedure 4

int main ()

{

printf (//"itcast\n");

return 0;

}

    1. Procedure 5

int main ()// Main function {

printf ("itcast\n");

return 0;

}

?

Content Source: Preach intelligence podcast Li Mingjie teacher Content

C Language Section III keywords, identifiers, comments

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.