& Operators

Source: Internet
Author: User

The & operator can be either a unary operator or a two-dollar operator.

  Note

The unary & operator returns the address of the operand (requires an unsafe context).

For integral type andthe bool type pre-defines the binary & operator. for integer,&, the Logical bitwise "and" of the operands are computed.  bool operands, & Computes the logical AND of its operands; That is, the result was true if and only if both it operands is Span Class="input">true . For  , bool  operands,& The logical "and" of the operands, that is, when and only if the two operands are   true , the result is   true.

The & operator calculates two operators, regardless of the value of the first operand. For example:

  
 1  int  i = 0   2   False  & ++i = = 1  )  3  { 4  //  I was incremented, but the conditional  5   expression evaluates to False, so  6  //
      This block does not execute.  7 } 
View Code

User-defined types can overload the $ two & operator (see operator).  An operation that is applicable to an integer type usually applies to an enumeration type. when you overload the two-tuple operator, the corresponding assignment operator, if any, is also implicitly overloaded.

  Example

  
1 classBitwiseand2 {3     Static voidMain ()4     {5         //The following statements perform logical ANDs.6Console.WriteLine (true&false); 7Console.WriteLine (true&true); 8 9         //The following line performs a bitwise AND of F8 (1111) andTen         //3F (0011 1111). One         //1111 A         //0011 1111 -         //    --------- -         //0011 or a theConsole.WriteLine ("0x{0:x}",0xf8&0x3f);  -     } - } - //Output: + //False - //True + //0x38
View Code

& Operators

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.