Go language "Fourth": Go operator

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

Go language operators

Operators are used to perform data or logical operations while the program is running, and the built-in operators of the Go language are:

    • Arithmetic operators
    • Relational operators
    • logical operators
    • Bitwise operators
    • Assignment operators
    • Other operators

Arithmetic operators
The following table lists the arithmetic operators for all the go languages, assuming a value of 10,b is 20;

operator Description Example
+ Add A + b Output result 30
- Subtraction -B Output Result-10
* Multiply A * b Output result 200
/ Divide B/A Output Results 2
% Seeking redundancy B% A output result 0
++ Self-increment a++ Output Results 11
-- Self-reduction a--Output Results 9

The following examples demonstrate the use of each arithmetic operator:

 PackageMainImport "FMT"funcMain () {varAint= +    varBint=Ten    varCintc = A + b fmt. Printf ("First row-the value of C is%d\ n"c) C = A-B fmt. Printf (the second row-the value of C is%d\ n", c) C = A * b fmt. Printf ("Third row-the value of C is%d\ n"c) C = A/b fmt. Printf ("line fourth-C has a value of%d\ n", c) C = a% B fmt. Printf ("line fifth-C has a value of%d\ n", c) a++ FMT. Printf ("line sixth-A has a value of%d\ n", a) a= + //For testing convenience, a here is re-assigned toa--FMT. Printf ("line Seventh-A has a value of%d\ n", a)}

The result of the above example operation:

3111210212220

Relational operators
The following table lists the relational operators for all the go languages, assuming a value of 10,b is 20:

Go language "Fourth": Go operator

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.