C language keywords (2)

Source: Internet
Author: User

C language keywords (2)
10. goto keywords

In general, the encoding level is inversely proportional to the number of times used by the goto statement.
In my opinion, disable the goto statement.
11. void keyword
1. void modifier function return values and parameters
1> If the function does not return a value, declare it as void.
2> If the function has no parameters, you should declare the parameter as void.
2. void pointer
1> you cannot perform algorithm operations on the void pointer.
2> If the function parameter can make any type of pointer, you should declare its parameter as void *
3. void cannot represent a real variable.

12. return keyword
Return is used to terminate a function and return the value following it.
Return (Val); // This bracket can be omitted, but it is generally not omitted, especially when the value of an expression is returned;
Note: 1> A function can have multiple return statements, but only one return statement is executed.
2> the return statement cannot return the "Pointer" pointing to "stack memory" because the function is automatically destroyed when the function ends.
13. const keywords
1. Read-Only variable modified by const
Defines the const read-only variable, which is non-mutable.
Note: Read-Only variables modified by const must be initialized at the same time as defined.
2. Save space to avoid unnecessary memory allocation and improve efficiency
Generally, the compiler does not allocate memory space for common const Read-Only variables, but stores them in the symbol table. This makes it a value during the compiler and does not have operations to store or read memory, this makes it highly efficient.
3. Modify common variables
Int const I = 2; or const int I = 2;
4. Modify the Array
Read-Only array: int const a [5] = {1, 2, 3, 4, 5 };
Const int a [5] = {1, 2, 3, 4, 5 };
5. Modify the pointer
Const int * p; // p variable. The object pointed to by p cannot be changed.
Int const * p; // p variable. The object pointed to by p cannot be changed.
Int * const * p; // p is unchangeable, and the object pointed to by p is variable.
Const int * const * p; // the pointer p and p point to the object are not changeable
6. Modify function parameters
This parameter is used when you do not want the parameter value to be accidentally changed in the function body.
Example: void Fun (const int I );
7. Modify the return value of a function
1> the const modifier can also modify the return value of a function. The return value cannot be changed.
Example: const int Fun (void );
2> reference the const read-only variable in another connection file
Extern const int I; // correct statement
Extern const int j = 10; // error. The value of the read-only variable cannot be changed.

14. volatile keywords
Volatile is variable and unstable.
The volatile keyword is a type modifier like const. Variables modified by volatile indicate that they can be changed by unknown factors in some compilers, such as the operating system,
15. extern keyword
Use extern to declare variables or functions defined in another file.
16. struct keywords
Struct is a magic keyword that packs associated data into a whole for ease of use.
1. struct size
2. Flexible Array
17. union keyword
The usage of the union keyword is very similar to that of struct.
Union maintains sufficient space to place "one" among multiple data members, rather than configuring space for each data member. All data members in union share one space. Only one data member can be stored at a time. All data members have the same starting address.


18. enum keywords
Enumeration and # define macros
1> # define macro constants are replaced in the pre-compilation phase, while enumeration constants are determined during compilation.
2> generally, you can debug enumeration constants in the compiler, but not macro constants.
3> enumeration can define a large number of related constants at a time, while # define macro can only define one.
19. typedef keyword
Note the difference between typedef and # define.
# Define INT32 int
Unsigned INT32 I = 10; // correct
Typedef int int32;
Unsigned int32 j = 10; // compilation Error

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.