C language Keywords (ii)

Source: Internet
Author: User

Ten. Goto keyword
in general, the level of encoding is inversely proportional to the number of times the goto statement is used.
Personal Assertion, disable goto statement.
one. void keyword
1. Void modifier function return value and parameter
1> If the function does not return a value, it should be declared as void type.
2> If the function has no arguments, declare that its argument is void
2. void Pointer
1> cannot perform algorithmic operations on void pointers
2> If the parameters of a function can make any type of pointer, then the argument should be declared void*
3. Void cannot represent a real variable

A. return keyword
Return is used to terminate a function and return the value followed by it.
return (Val); //This parenthesis can be omitted, but generally not omitted, especially when returning the value of an expression;
Note: 1> can have multiple return statements within a function, but only one return statement is executed
The 2> return statement cannot return a pointer to "stack memory" because the memory is automatically destroyed at the end of the function.
The. Const keyword
1. Const-Modified read-only variable
defines a const read-only variable with immutability.
Note: A const-Modified read-only variable must be initialized at the same time as defined.
2. Save space, avoid unnecessary memory allocation, and improve efficiency
.
instead of allocating memory space for ordinary const read-only variables, the compiler saves them in the symbol table, which makes him the value of a compiler, without the storage and read memory operations, making it highly efficient.
3. Modifying general variables
int const i = 2; or const int i = 2;
4. Modifying Arrays
reading Group: int const A[5] = {1,2,3,4,5};
const int A[5] = {1,2,3,4,5};
5. Modifier pointers
const int *p; / /P variable, p-pointing object immutable
int const *p; / /P variable, p-pointing object immutable
int *const *p; / /P immutable, p-pointed object variable
const int *const *p; / /The object that the pointer p and P point to is immutable
6. Parameters of the modifier function
Use when you do not want the parameter value to be changed unexpectedly in the function body.
Example: void fun (const int i);
7, the return value of the modifier function
The 1> const modifier can also modify the return value of a function, and the return value cannot be changed.
Example: const int fun (void);
2> references a const read-only variable in another connection file
extern const int i; / /Correct declaration
extern const int j = 10; / /error, the value of the read-only variable cannot be changed

. volatile keyword
volatile is a volatile, unstable meaning.
The
volatile keyword, like const, is a type modifier, and a variable that is decorated with it can be changed by factors unknown to the compiler, such as the operating system,
The. extern keyword
use extern to declare when referencing a variable or function defined in another file
. struct keyword
A struct is a magical keyword that packs some of the associated data into a single whole for ease of use.
1, the size of the structure of the body
2. Flexible Arrays
The. Union keyword
the use of the Union keyword is very similar to the use of a struct.
Instead of configuring space for each data member, the union maintains enough space to place "one" in multiple data members. All data members in the Union have a common space, where only one of the data members is stored at the same time, and all data members have the same starting address.


. enum keyword
Differences between enumerations and #define Macros
1> #define Macro constants are simple replacements during the pre-compilation phase; Enumeration constants determine their values at compile time
2> General in the compiler, you can debug enumeration constants, but you cannot debug macro constants.
3> enumerations can define a large number of related constants at once, and a # define macro can only define one at a time.
. typedef keywords
Notice the difference between typedef and #define
#define INT32 INT
unsigned INT32 i = 10; //correct
typedef int Int32;
unsigned int32 j = 10; / /Compilation Error

C language Keywords (ii)

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.