How the Monocular and binocular operators and the three-mesh operator

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

1, monocular operator:

The monocular operator is an operator, called a unary operator, that requires a variable to be an operation, with a logical non-operator:!, bitwise negation Operator: ~, self-reducing operator: ++,–.
Logical non-operator "!", bitwise negation operator "~", self-decrement operator "++,–", minus sign operator "-", type conversion operator (type), pointer operator and address operator "* and &", length operator "sizeof"

2, binocular operator:

The binocular operator is an operation on two variables
The elementary operator subscript operator "[]", the component operator points to the struct member operator "->", and the struct body member operator.
Arithmetic operators
Multiplication operator "*", Division Operator "/", remainder operator "%", addition operator "+", subtraction operator "-"
Relational operators
equals operator "= =", not equal to operator "!=", relational operator "< > <= >="
logical operators
Logical AND Operator "&&", Logical OR operator "| | ", logical non-operator." 】
Bitwise operators
Bitwise AND Operator "&", bitwise XOR or operator "^", bitwise OR operator "|", left move Operator "<<", Right move operator ">>"
Assignment operator
Assignment Operator "= + = = *=/=%= >>= <<= &= |= ^="
Comma operator
Comma operator ","

3, three-mesh operator:

operation of three variables;

The three-mesh operator operates on three variables and refers to an important part of the computer C language. The conditional operator is the only operator with 3 operands, so it is sometimes called a ternary operator. In general, the combination of the three-mesh operator is right-bound.
For conditional expression B? X:y, first calculate the condition B and then make a judgment. If the value of B is true, the value of x is computed and the value of x is computed, otherwise, the value of y is calculated, and the result is the value of Y. A conditional expression will never compute both X and Y. The conditional operators are right-bound, that is, grouped from right to left. For example, a? B:c? D:e will press a? B: (c. d:e) implementation. [1]
< expression 1>? < expression 2>: < expression 3>; “?” The meaning of an operator is to first evaluate the value of expression 1, and if true, execute Expression 2 and return the result of expression 2; If the value of expression 1 is false, execute the expression 3 and return the result of expression 3.
Can be understood as a condition? Result 1: The result 2 inside. The number is a format requirement. It can also be understood that the condition is not set up as a result of 1 otherwise 2.
Note: In the C language, the type of result 1 and result 2 must be the same.

int a = 1, b = 2, Z, c = 3;

Z = a > B? A: (b > C. b:c);

cout << "z:" << z << endl;
The result of this output is: Z:3

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.