Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C language keywords Comments     - Interesting example of Linux Sort command (Linux)

- Linux + Apache + PHP + Oracle based environment to build (Server)

- Spring Data MongoDB combat (Database)

- HBase cluster installation and deployment (Server)

- CoreOS Linux introduces Kubernetes kubelet (Server)

- exp / imp Export Import version of the problem and the ORA-6550 error (Database)

- Sublime Text 3 (Linux)

- Source compiler install Nginx (Server)

- How to install Ubuntu strategy game Wesnoth 1.12.0 (Linux)

- Linux System Getting Started Learning: DeVeDe installed on Linux to create a video DVD (Linux)

- Install Unity 8 preview version of the desktop in Ubuntu (Linux)

- CentOS and RHEL to install IPython 0.11 (Linux)

- KVM virtualization nested configuration (Server)

- Android imitation UC browser scroll up and down functions (Programming)

- Open log in Hibernate (Programming)

- Linux System Getting Started Tutorial: Five image processing software (Linux)

- Ubuntu modify locale problem solving (Linux)

- Linux Getting Started tutorial: 3D effects and beautify your desktop (Linux)

- SQL Server 2008 database synchronization Notes (Database)

- Ubuntu 12.04 LTS installation configuration JDK1.6.0_45 (Linux)

 
         
  C language keywords Comments
     
  Add Date : 2018-11-21      
         
         
         
  Respect for other languages, C language keywords considered small by. C98 in the key sub-total of only 32, we have to analyze each keyword in C language in its unique role.

1, on the data types of keywords

(1) char: char variable or function declaration
(2) double: double precision variable or function declaration
(3) enum: enum type declaration

enum types can increase readability and portability; each object in the enum defined in default are starting from 0, of course, can also be customized. as follows:

enum Color {RED, BLACK, WHITE};
enum Number {ONE = 1, TWO, THREE};

Color in RED = 0, BLACK = 1, WHITE = 2;

Number of ONE = 1, TWO = 2, THREE = 3;

(4) float: float variable or function declaration
(5) int: integer variable or function declaration
(6) long: long integer variable or function declaration
(7) short: short integer variable or function declaration
(8) signed: a statement signed type variable or function
(9) struct: declare a structure variable or function

Role structure struct is already on the blog post mentioned, can be used to implement the C language encapsulation, inheritance, polymorphism, and so on.

Refer http://www.cnblogs.com/whc-uestc/p/4677414.html
(10) union: union declaration (joint) data type

union type can be used to improve memory usage, as follows:


Copy the code
int main () {
    union Unoin {int a; float b; char * c;};
    union Unoin p;
    p.a = 100;
    / *
        Statement 1 is executed
    * /
    p.b = 10.0;
    / *
        2 Execute the statement
    * /
    p.c = "hello world!";
    / *
        3 Execute the statement
    * /

    return 0;
}

Copy the code

If you do not use the union, we need to define int, float, cahr *, take up 12 bytes of memory space, but when we use the union, can only take 4 bytes; however, when you need to pay attention, we are on top the code to execute the statement will need 2 or 3 int a, the union can not be used, and must be defined separately int a; otherwise a value read will be wrong.

(11) unsigned: declare unsigned type variable or function
(12) void: no return value or function declaration with no arguments, no declaration (basically these three roles) type pointer

2, on the control statement keywords

Loops

(13) for: iterative statements (any woman)
(14) do: loop body of the loop
(15) while: loop Conditional loop statements

Conditional statements

(16) if: Conditional statements
(17) else: conditional statements negative branch (and if used in conjunction)
(18) switch: for a switch statement
(19) case: a switch statement branch
(20) default: switch statement "other" branch

In case ... switch statement, a condition when the input from the condition that case statement begins execution until it encounters a jump instruction (break; return; goto; contine;), it is recommended that in the back of each case statement added on break, unless you deliberately do not do that.

Jump statement

(21) goto: Unconditional jump statement

With a goto statement can only export guarantee programs exist to avoid too large if nested, but feel free to use the goto statement the program will bring great risks (may skip initialization, it is important to calculate the variable statements, etc.) , affect code robustness and readability. It is not recommended to use too much.

(22) continue: the end of the current cycle and start the next cycle

(23) break: out of the current cycle

(24) return: subroutine return statement (with parameters can be without parameters)

Function All instructions are not executed after the return statement, so the need to ensure the necessary return statement before executing the instruction.

 3, on the storage types of keywords

(25) auto: automatic variable declaration are generally not used, because when we declare a local variable is the default is auto
(26) extern: variable is declared positive statement in other documents (also can be seen as a reference variable), generally require frequent use, because the C language, global variables and functions are the default attributes extern
(27) register: declare register variables declared register variables are stored in the registers inside the CPU, so the read speed is very fast, but a limited number, as defined by a plurality of register variables, the compiler converts the variable number of those who register as auto variables.
(28) static: static variable declaration

a, when we put a global variable declaration is static: only its scope into the origin of the file, which is the property of the external into internal, the other unchanged;

b, when we put the function is declared static: its scope into the origin of the file, which is the property of the external becomes internal;

c, when we put a local variable declaration is static: default initialization value is 0, and is initialized only the first time defined; memory storage areas is no longer stack, but in the static storage area; where the function is no longer lifecycle , but the entire process; the other unchanged.

4, a number of other keywords

(29) const: read-only variable declaration

Declared by the const variable must be initialized in the definition. as follows:

const int num = 10; // definition of the initialization, and the value of the variable is not allowed to change

Since the values of the variables are not allowed to change, then this variable defines dim? Haha, use a great deal. First, we define the array when the size of the array can be used to represent constants defined const, #define this just the same, but it is type-safe, # define a pre-command, just a simple character replacement, and the compiler const variable defined type checking; secondly, when we no longer need to change a variable, you can use const, for example, the definition of a person's sex, ever since you have been born to determine your gender, not surprisingly, then, this life will not change, so put it defines as read-only, of course, was also considered not to be defined as const Well, if he did not change it's OK, but if that's the case, it We need to artificially control, if one day forget, it changed how do? So it is best to define for some read-only or constant use const.

When we put the const pointer variables are placed together, the problem becomes complicated. For example, we are defined as follows:

const int * p1;
int const * p2;
int * const p3;
int const * const p4;

Pointer variable p1: const before the data type, the modified object p1 points, so p1 pointed object is read-only constants can not be changed, but p1 itself may change;

Pointer variable p2: const * before, this situation with the same p1;

Pointer variable p3: const after the *, the modified variable p3, so that p3 variable itself is constant read-only, and the object p3 points may vary;

Pointer variable p4: Object variable p4 and p4 have pointed to two const are modified, so the object itself and p4 p4 points are constant read-only, it can not be changed.

In fact, these are very easy to remember, just look const * is * in front or behind, in front * is a modified pointer points to an object in the * after the modification is the pointer itself.

Here to give a simple example:


Copy the code
int main () {
    int num1 = 0;
    int num2 = 1;
    int num3 = 2;
    int num4 = 3;
    const int * p1;
    int const * p2;
    // Int * const p3; // error (1)
    int * const p3 = & num3;
    // Int const * const p4; // error (2)
    int const * const p4 = & num4;
    p1 = & num1;
    // * P1 = 100; // error (3)
    num1 = 100; // At this point * p = 1;
    // P3 = p4; // error (4)
    * P3 = 100;
    // P4 = p3; // error (5)
  
        return 0;
}

Copy the code

In the above code, error (1) and error (2) it is easy to understand, because the const after the *, so the pointer p3, p4 itself is read-only, must be initialized in the definition. error (3) because the p1 pointer, const * before, so the object p1 points can not be changed. error (4) and error (5) because for p3, p4, have const after the *, so the pointer itself is read-only after initialization, it can not be changed.

(30) sizeof: Calculation Data Type Length

Many people do not understand the difference between sizeof and strlen is: sizeof operator is, and strlen is a function; sizeof calculates the sizes of data types, and strlen calculates the length of the string; sizeof parameter can be either a data type to be is variable, strlen parameters can only be char *, and must be null-terminated; sizeof return value type is unsigned, and strlen return value is signed, because it needs to return a negative number to indicate an error condition.

(31) typedef: to give the data type alias

typedef in programming which is useful when a data type for a long time (for example, a function pointer), we can use typedef to choose an appropriate name to replace it; when we use int, float, double these types, you can also use your favorite name and intuitive to redefine it so that when we later need to project into double type float type, we can put directly on the typedef float into double can, without We need to put all the code inside each float into double.
(32) volatile: explanatory variables during program execution can be implicitly changed

volatile variables do not allow the compiler to do with it any operational optimization; volatile variables defined outside may be changed in the program, so each must be read from memory, he can not be placed or cache register reuse. Generally used in the following places:

a, parallel device hardware registers (eg: status register)
b, an interrupt service routine will have access to the non-automatic variable (Non-automatic variables)
c, multi-threaded application variables are shared by several tasks
     
         
         
         
  More:      
 
- How to use the beta / unstable version of the software in Debian library (Linux)
- About Leetcode on Binary Tree Algorithm summary (Programming)
- How to install and use the malware detection tool LMD and ClamAV antivirus engine on Linux (Linux)
- IP Security Policy is to learn how to prevent Ping and closed ports (Linux)
- Linux command ls (Linux)
- DM9000 bare Driver Design (Programming)
- To install Ganglia (Linux)
- wget command Walkthrough (Linux)
- Asynchronous JavaScript loading (Programming)
- Compile and install GCC 4.8.1 + GDB 7.6.1 + Eclipse in CentOS 6.4 in (Linux)
- Java NIO1: I / O model overview (Programming)
- Error: Unable to establish connection with FTP SFTP server (Server)
- Define and modify strings principle in Python (Programming)
- 11 you Linux Terminal Command (Linux)
- Customize the output format in Linux history (Linux)
- The AWK use Cygwin tools mysql binlog log viewer (Database)
- Java threads and thread pools (Programming)
- The direct insertion sort algorithm (Programming)
- Practical Handbook: 130+ improve the efficiency of commonly used commands Vim (Linux)
- Hadoop 2.2.0 installation development environment (standalone pseudo-distributed mode) (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.