C + + Offal syntax

Source: Internet
Author: User

C + + Boolean type in: Boolean type takes only one bit, but if multiple Boolean types are defined consecutively, the compiler may define multiple Boolean types together. The true compiler is represented by a. False The compiler is represented by the.

assign a different type of data to a Boolean type variable: The C + + compiler converts all non-0 values to True (1) and converts 0 to False (0).

Tri-Wood operator    ? :: A three-mesh operator as an lvalue: (a>b?a:b) = 3 The C language is not supported (the Trinocular operator returns a value), but is supported in C + + (a trinocular operator returns a variable). But if one of the possible return values is a constant value, then it cannot be used as an lvalue, such as (a>b?1:b) = 3 illegal.

Reference:

C + + references in: an alias for a variable that has already been defined. Type Var, type & name = var; A normal reference must be initialized with a different variable when declaring. The reference is not initialized when declared as a function parameter.

Const modifier Reference:const causes the reference to have a read-only property, but the variable itself is the original property.

When a const reference is initialized with a constant, the compiler allocates space for the constant and names the reference name as an alias for the space. You cannot assign a constant to a normal reference, but you can assign a constant reference to a const value. A constant reference is read-only at this time, and it cannot be assigned a value except when it is defined. Therefore, a constant reference can be used to form a read-only variable, such as a const int & a = Ten A is a read-only variable.

reference in C + + the internal implementation is a constant pointer:type & nameßàtype* const name. So the reference has a 4-byte space.

reference as a function return value: when a reference to a local variable is returned, the reference cannot be an lvalue, nor can it be used to initialize other references, but it is possible to refer to a static or global variable if referenced.

C + + function Exploration:

    1. Inline functions:inline int function (...), inline functions can replace the macro code snippet, at compile time the function body directly replace the function is called place, thus reducing the ordinary function is called when the cost (stack, jump, etc.), But an inline function is essentially a function, unlike a macro code fragment. Inline function Declarators must be combined with the function definition and cannot be placed at the declaration, otherwise the compiler ignores the inline request. While inline functions save time and space, the compiler does not necessarily allow inline requests for functions, and inline functions are treated as normal functions when the C + + compiler does not allow inline requests.
    2. Default parameters: In C + +, you can provide a default value for a parameter when the function is declared, and when the function call does not provide a value for the parameter, the compiler automatically replaces it with the default value. However, the default parameter value is not specified when the function is defined. The default parameter has the following rules:

Only some of the parameters that follow the argument list can provide default parameter values, but when you start using default parameters in a function call, all parameters after this parameter must use the default parameters, so the parameters that follow the start of using the default parameters are provided with default parameters, or the compiler will give an error. In summary, when a function is declared, if a parameter is supplied with a default argument, all subsequent arguments are provided with default parameters, and when the function is called, all subsequent arguments use the default parameters if they start omitting the arguments.

    1. function Placeholder parameter: The placeholder parameter is only a type declaration when the function is defined, and there are no parameters declared by the parameter name. In general, placeholder parameters cannot be used inside the function body. However, the full number of arguments must be provided at the time of invocation. You can provide default parameters for a placeholder parameter. Meaning: For the subsequent version of the function of the expansion of the foreshadowing, compatible with the C language of the non-standard notation.

C + + Offal syntax

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.