C language keywords (1), C language keywords

Source: Internet
Author: User

C language keywords (1), C language keywords
0. Differences between definitions and declarations

1. What is definition?
The so-called definition is that the compiler creates an object, allocates a piece of memory for this object and gives it a name. This name is what we often call the variable name or object name. Once the name matches the memory, they will die together, and the memory location cannot be changed. A variable or object can only be defined once in a certain region.
2. What should I declare?
The Declaration tells the compiler that the name has been matched to a block of memory and can appear multiple times. It also tells the compiler that the name has been defined and cannot be used as a variable or object name elsewhere.
3. What are the differences between declarations and definitions?
Definition: if an object is created, do not allocate memory for the object. It is declared that no memory is allocated.


1. A large number of keywords ---- auto
Auto: by default, the compiler defaults to auto for all variables.
2. The fastest keyword ---- registr
Register: This keyword requests the compiler to store variables in the internal registers of the CPU as much as possible, rather than accessing through memory addressing to improve efficiency. Note that it is possible, not absolute.
Note: 1. The register variable must be a type that can be accepted by the CPU register. This means that the register variable must be a single value and its length should be less than or equal to the length of an integer.
2. The address of the register variable cannot be obtained using the "&" accessors.
3. Keyword ---- static
1. Modify Variables
1> static global variables
The scope is limited to files where variables are defined. Other files cannot use them even if they are declared using extern.
To be accurate, the scope starts from the definition and ends at the end of the file. The code before the definition cannot use it. If you want to use it, add the extern before it ***
2> static local variables
Defined in the function body can only be used in this function, and other functions in the same document cannot be used.
Because static modified variables always exist in the static memory zone, the value of this static variable will not be destroyed even after the function is run. This value can still be used by the function for the next time.
2. Modifier
Purpose: Add static before a function so that the function is called a static function. However, the meaning of "static" here is not the storage method, but the scope of the function is limited to this file.
Benefit: when different people write different functions, you don't have to worry about whether the defined function will be the same as the function in other files.
4. Basic data types ---- short, int, long, char, float, double
1. variable naming rules
***


5. The most embarrassing keyword ---- sizeof
1. sizeof is a keyword rather than a function.
2. sizeof occupies a large amount of space for computing variables. Brackets can be omitted, but the calculation type cannot be ignored.

6. signed, unsigned keyword
The basic data type is used to store the symbol bits. If the highest bit is 1, it indicates that this number is a negative number, and its value is the value of the remaining bits except the highest bit "-"
If the highest bit is 0, it indicates that this number is a positive number, and its value is the value of the remaining bit except the highest bit.

7. if, else combination
1. Which is else match?
Else always works with the if statement that matches the lowest end in the same bracket.
The delimiters "{" and "}" in the program are aligned.
2. semicolon after the if statement
If statements followed by semicolons do not produce errors, but different results may occur. Note that.
3. Other questions about using the if statement
1> handle normal conditions before handling exceptions.
2> make sure that the if and else clauses are not reversed.
8. switch, case combination
The use of switch and case combination can improve efficiency.
1. Never forget to add break at the end of each case statement; otherwise, multiple branches overlap.
2. The default branch must be used at the end, even if the program does not need to use: default: break;


9. do, while, for keywords
1. 3 cycles
1> while LOOP
While (1) indicates an endless loop
It can also be written as: while (true), while (1 = 1), while (bool) 1), etc.
First, judge the value in the parentheses after while. If it is true, execute the code behind it. Otherwise, the Code is not executed.
2> do-while loop
First execute the code after do, and then judge the value in the brackets after while
If it is true, the loop starts. Otherwise, the loop does not start.
3> for Loop
For loop can easily control the number of times, many of which are used to know the number of cycles in advance.
2. Difference Between break and continue
Break: Terminate the cycle of the current layer.
Continue: Terminate this loop. When the execution reaches the continue, the current cycle ends and enters the next cycle.
3. Notes for loop statements
1> if possible, the longest cycle should be placed in the innermost layer, and the shortest cycle should be placed in the outermost layer to reduce the number of cross-cycle CPU layers.
2> we recommend that you use "half-open and half-closed" to write the value of the for statement's cyclic control variable, which is more intuitive.
3> the loop should be as short as possible to make the code clear and clear at a glance.
4> Control nested loops within three layers.

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.