Fourth C + +: Application of expression concept-operator

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise operators

Describes the operators that are defined by the language itself and used for built-in type operands, while briefly introducing the operators of several standard library definitions.

Fourth Chapter expressions

Basic concepts

    • Unary Operators : Operators acting on an operand

    • two-tuple operator : operator that acts on two operands

    • A function call is also a special operator that has no limit on the number of operands

    • Lvalue: When an object is treated as an lvalue, the object's identity (in-memory position) is used.

    • Right value: When an object is treated as an rvalue, the value of the object (the content) is used.

Order of Evaluation

    • In most cases, the order of evaluation is not explicitly specified. Only four operators explicitly specify the order in which the operands are evaluated:

      1. Logic and Operators (&&): to the left to seek the right, only when the left is true to calculate the right value 2. Logical OR operator (| | ) 3. The conditional operator (?:) 4. Comma operator (,)

Arithmetic operators

BOOL B = True;bool B2 =-B;   B2 is true. -1 is not equal to 0, so the value of B2 is True
    • C++11 stipulates that the quotient shall be rounded to 0 (i.e. direct removal of the minor part).

    • If m%n is not equal to 0, then its symbol is the same as M:

      (-M)/N and m/(-N) are equal-(m/n) m% (-N) equals m%n (-m)%n equals-(m%n)

Logical AND relational operators

A relational operator acts on an arithmetic or pointer type, and the logical operator acts on any type that can be converted to a Boolean value.
-Their return values are Boolean types.

Logic with &&, logic, or | |

    • Short-circuit evaluation (short-circuit evaluation)

Relational operators

The evaluation result of a relational operator is a Boolean value that can be used together to produce unexpected results:

if (I < J < k)   //If k is greater than 1 is true

should read:

if (I < J && J < K)

Assignment operators

    • Assignment operator The left operand of the fly must be a modifiable lvalue.

    • If the left and right two operand types of the assignment operator are different, the operand to the left will be converted to the type of the operand on the side.

Assignment arithmetic satisfies right binding law

int I, j;i = j = 0;  Correct, all assigned to a value of 0

Conditional operator?:

Cond? Expr1:expr2

Satisfies the right binding law, and the operands are generally grouped in right-to-left order.

Bitwise operators

An operand that acts on an integer type, and an operand of a standard library type named Bitset.

~   : Bit negation <<  : Shift left >>  : Right Shift &   : Bit and ^   : bit xor |   : Bit or

sizeof operator

Returns the number of bytes, the resulting value is a size_t type.

There are two different forms: sizeof (type) sizeof expr
    • Satisfies the right binding law.

Type conversions

Implicit type conversions

In most cases, the array is converted into pointers .
-The conversion does not occur when the array is used as an operand to the Decltype keyword parameter, or as an operator of the accessor (&), sizeof, and typeid.

Show transformations

    • Named coercion type conversions

cast-name<type> (expression)

There are several cast-name:

dynamic_cast        //runtime type identification static_cast         //Can be cast as long as it does not contain the underlying const, telling the compiler not to care about the loss of precision const_cast          // You can only change the underlying const of an operand, known as the cast away the Const. Converts a constant object to a very mass object. Reinterpret_cast    //

Reference: C++primer Fifth Edition

Describes the operators that are defined by the language itself and used for built-in type operands, while briefly introducing the operators of several standard library definitions.

Related articles:

Chapter One C + +: function return value, GNU compiler command

chapter II C + +: Variables and basic types

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.