Summary of key points of C + + review (i.)

Source: Internet
Author: User
C + + 's strengthening of language--type strengthening

1. Register keyword Enhancement

Register keyword requests the compiler to put the variable directly inside the register, fast.

The register-modified variable in the C language cannot take the address, and the address can be taken in C + +.

2. Variable Detection Enhancements

In C language, it is legal to repeatedly define multiple global variables with the same name, and in C + +, it is not allowed to define multiple global variables with the same name.

3. All variables and functions in C + + must have a type

In the C language

int f (); A function that represents a return value of int that accepts arbitrary arguments

int f (void); An parameterless function that represents a return value of int

In C + +

int f (); and int f (void) have the same meaning, all of which represent an argument function with a return value of int

4. Three Mesh operator Enhancements

Example:a< B? A:B) = 30;

Difference: The C language Returns the value of the variable, and the C + + language is the return variable itself

The three-mesh operator in the C language returns the value of the variable and cannot be used as an lvalue

The three-mesh operator in C + + can return directly to the variable itself, so it can appear anywhere in the program

Note: If one of the values returned by the three-mesh operator is a constant value, it cannot be used as an lvalue (a < b? 1:b) = 30;

How does the C language support features like C + +?

====> when the condition of an lvalue: to have memory space; C + + compilers help programmers take an address

1.const Qualifier Recognition

Function: Converts an object into a constant, read-only.

int main () {const int a;//1 1th 2nd meaning represents a constant shaping int const b;//2CONST int *c;//3 3rd C is a pointer to a constant number (the memory data pointed to cannot be modified, but can be modified by itself ) int * Const D; 4 4th D constant pointer (pointer variable cannot be modified, but it points to memory space can be modified) const int * Const E; 5 5th e A pointer to a constant shape (the pointer and the memory space it points to cannot be modified) return 0;

Example:

const int Bufsize=512;bufsize cannot be modified after initialization. 1) in C + +, the const symbol table principle: storage is a symbol table that is key Valuekey valuebufsize 512

2. How the C + + compiler handles Const constants: When a constant is declared, it is placed in a constant in the symbol table, and the value in the symbol table is replaced directly with the constant.

Conclusion: The difference between C language and const variable in C + +

The const variable in C is a read-only variable with its own storage space

Const constants in C + +

May allocate storage space, or may not allocate storage space

When the const constant is global and needs to be used in other files

When using the & operator to take the address of a const constant

2) const and #define异同之处

Same: Both can be used as constants

XOR: Const constants are handled by the compiler, providing type detection and scope checking, macro definitions handled by the preprocessor, and simple text substitution.

The above is the summary of C + + review (a) of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.