C language advanced Summary 1

Source: Internet
Author: User

1. good at using symbolic constants.

It is no good to bury a number in a program. On the one hand, it cannot provide information to people looking at your program in the future. On the other hand, it is also very troublesome to modify the number.

You can use define to define symbolic constants.

# Define the actual number or Character Sequence of the name you want to use/* The symbol constant is generally in upper case, which is different from the variable in lower case */

For example: # define MAX 100

Note 1:The symbolic variables defined by define are non-typed, and compilation is not performed for security detection, which is prone to problems. Therefore, some people say that using const can completely replace define,

And better.

For example, const int MAX = 100

NOTE 2:Define is a replacement.

For example: # define A 3 + 5

Const int A = 3 + 5

In A formula, 3 * A is equivalent to 3*3 + 5 = 14.

In formula 2, 3 * A is equivalent to 3*8 = 24.

Note 3: The const keyword does not really represent A constant. If the previous expression A is substituted into the switch statement,

Case:

An error may also occur.

If you want to further investigate the differences between them

2. The getchar () function returns int-type data.

int c;c=getchar();


3. Be careful when the compiler compilation fails due to the greedy method.

For example, divide x by the value pointed to by p, and assign the value to Y.

D: Y = x/* p;

However, the compiler will regard/* as the beginning of the annotation and assign x to Y directly.

The correct method is Y = x/(* p)

4. A single quotation mark is equivalent to a number. '\ 0' is at the end of the double quotation mark'

5.

Float * g () refers to a pointer of the floating point type returned by the g () function.

Float (* g) () is a function pointer to the returned floating point type.

6. Multiple operators should be placed in parentheses in the calculation order to avoid incorrect operations due to symbol priority issues.

7. Be careful with the semicolon position after if, for, and while. Pay attention to the break after case and the last default position in switch.

If you intentionally do not add a break statement, you can write a comment to indicate it.

8. In C language, else always matches the nearest IF

If

If

Else

This structure will automatically become

If

If

Else

(Unlike PYTHON, indent alignment is fine)

Therefore, we need to develop good habits.

If

{

If

}

Else

In this way, we want to match the first IF because the second IF is "encapsulated ".

9. the operation on the array is the operation on the pointer. The array is used as a parameter to be substituted into the function. In fact, it is a pointer to the first element.

Main (int argc, char * argv [])

{

}

Equivalent

Main (int argc, char ** argv)

{

}

10. Data boundary issues. Avoid railing errors.

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.