Summary of key words in C language

Source: Internet
Author: User
Tags define null modifier volatile

Register:

Define variable is register save, not write to memory

    1. The address cannot be taken because it is on the register
    2. Unable to save data stored in information and BSS segments
    3. registers are equivalent to memory cache, which increases access speed, but how many of them can be saved by the CPU , and the excess will be ignored.

Static:

Static modifier variables:

    1. Static modifies the local variable, initializes it the first time it encounters it, and stores the data in the database segment, so the function stack pin is not destroyed when it is rolled back and destroyed after the program ends.
    2. Static modifier global variable: Unlike global variables, other files cannot find the address of this variable symbol at link time.
    3. In C + + , global variables affect encapsulation, are implemented using static data members defined within a class through scope access, and therefore do not have the same name as global variables (typically defined within a class, and are initialized outside of the class).
    4. A static decorated data member in C + + can no longer be initialized with a constructor, and needs to be initialized at the time of definition. Only static normally shaped variables can be initialized within a class (static const int).

Static modifier function:

    1. The function plus static in C language declares that this function cannot be found at link time, only visible in this file.
    2. inC + +, thestatic decorated function does not Pass in the this pointer, so it cannot access the object's non- static data members.

NULL:

in C language #define NULL ( void* ) 0 p = = NULL p = = 0 c++ #define NULL 0 nullptr null

Switch and case:

    1. Attention Remember break
    2. The floating-point number is not accurate
    3. switch is more efficient than if else , because viewing disassembly finds the use of register-saving values to directly compare and then jump, and if else Each time you need the value of the op-expression to jump.

Const:

Const is a constant variable in C language cannot be left value

Const Constants in C + + must initialize symbols as local plus extern variable Global

The constant name is replaced with the initial value of the constant during compilation

The compiler must ensure that the amount of the Const modifier cannot be modified directly or indirectly (attempting to assign a constant address to a normal pointer)

If the initial value is a variable then degenerate into a constant variable

Const & Reference constants (addressable constants and non-addressable constants)

Const to the right without any pointers to the type, the reference does not participate in the type

volatile :

make a variable not be cached in a multithreaded program Guaranteed Visibility of the data no guarantee of atomicity

1. prevent the compiler from ordering optimization of assembly instructions

    1. compiler tuning volatile for order of instruction
    2. when the program runs CPU Tuning of the order of instructions barrier()

2. preventing copy values of register storage variables

struct and class differences:

variable functions can be defined in both 1.strcut and class to achieve polymorphic inheritance

2.struct more inclined to define data types,class is biased towards defining objects and methods

3.class inherits default private,struct inherits default public

4.class can use template,struct no

for an empty struct and class to distinguish between different structures (objects), assign at least one byte to store him, and pay attention to memory alignment.

The method of judging the small end of big-endian:

    1. Judging by the Union
    2. printf judgment
    3. Fetch address strong turn after dereference

malloc,realloc,calloc

malloc requests a piece of memory from the heap ( an anonymous mapping is called over the mmap threshold).

Calloc can be initialized after allocation.

ReAlloc expansion to the new size, problems that may occur:1. function is prone to ambiguity, causing memory leaks 2.realloc may move locations, andobjects inC + + may cause memory leaks by referencing external resources.

Summary of key keywords in C language

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.