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