C language entry: 03. keywords, identifiers, comments, language entry 03

Source: Internet
Author: User

C language entry: 03. keywords, identifiers, comments, language entry 03
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, if you have mastered a high-level language and want to learn other advanced languages, it is quite fast.

(4) In addition, many other advanced languages, such as Objective-C, which will 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, are symbols used to identify something. The purpose of identifiers is to distinguish these things.

(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)

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

  ·It is case sensitive. For example, test and Test are two different identifiers.

  ·Cannot start with a number

  ·You cannot use keywords as identifiers.

(2) Naming rules (preferably observed)

Try to create a meaningful name, for example, a complete English word. When someone else looks at the name, the identifier can be used. If you do not understand English, you can also use Pinyin. Try not to use meaningless names such as abcde and sfsdfsdf.

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 underscore _ to connect: first_name, my_first_name

4. common identifier naming errors 5. Exercise

Identifies correctness

test1 Mike2jack My_tExt _test

test! 32 haha (da) tt haha_text 123haha

78text 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) The comment in development tools is generally bean paste green

2. Single Row comment

(1) A single line comment starts with two forward slashes, that is, it starts with //. Only one line can be commented. From // to the end of this line, the Comment content is

(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 will not participate in compilation

  ·Annotations are intended for users rather than 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.

  ·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 errors

5. annotation nesting

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

// wow ha ha // ha ha ha

// / * 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 a C program

* /

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

/ * Hahaha

   /*Hee hee hee*/

    Ha ha ha * /

(4) The following statements are incorrect.

// / *

Hahaha

* /

6. Importance of annotations

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)

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.

You have been in a company for more than a 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) Procedure 1

// main function
int main () {

     printf ("itcast \ n");

     return 0;
}

(2) Procedure 2

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

(3) Procedure 3

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

(4) Procedure 4

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

(5) Procedure 5

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

 


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.