C and pointer (pointers on C) -- Chapter 2: Basic Concepts

Source: Internet
Author: User

C and pointer (pointers on C) -- Chapter 2: Basic Concepts
Chapter 2 Basic Concepts


Poor code style and poor documentation directly lead to high costs for software development and maintenance.
In fact, a person always has his own code style, mainly sticking to a reasonable style, so that everyone can easily understand it.


Summary:
C is a case-sensitive language, so Abc and abc are two different identifiers. The length is not limited, but 31 characters will be ignored automatically.
The starting point of the program is the main function. Most environments use stacks to store local variables and other data.
Annotations must start with/*, */, and nesting is not allowed. Annotations will be removed by the pre-processor.
An identifier consists of numbers and underscores. It cannot start with a number.
Keywords cannot be used as identifiers.


Warning:
1. Comments may occasionally abort statements.


Programming tips:
It is best to develop a good program style and document style.
For example:
1. Empty rows. Identifies different logical code segments. The end of a function can be seen at a glance.
2. Leave a space between the brackets and expressions of if to make the expression more prominent.
3. leave spaces in most operators. Of course, expressions that are too complex can be ignored.
4. nested statements use tabs. If empty rows are too long, too many nested statements can be replaced by other functions.
5. Comments should appear in blocks.
6. In the function definition, the return type is an independent row. The function name can start at the beginning of the next row.




Some Questions about the selection:
1. What are the advantages and disadvantages of putting a large program into a single source file?
Advantage: avoids repeated definition errors. Avoid declaration.
Sure: Obviously, the c file of a 40 thousand-line program is terrible.
2. Write a program that reads the C source code from the standard input and verifies that all curly brackets appear in a correct place.

// Enter curly brackets in pairs. cpp: defines the entry point of the console application. // # Include "stdafx. h "# include" stdio. h "# include" stdlib. h "int _ tmain (int argc, _ TCHAR * argv []) {int Add = 0; char temp; while (temp = getchar ())! = EOF) {if (temp = '}') {if (Add = 0) {printf ("wrong! ");} ElseAdd-= 1;} if (temp = '{') {Add + = 1 ;}} return EXIT_SUCCESS ;}


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.