- Operators are used to perform operations on variables and values.
- Operators allow operands to be combined into expressions
- Operators are either binary operators or unary operators. A binary operator operation takes two operands and a unary operator operation takes only one operand.
Arithmetic Operators
-
To demonstrate the use of arithmetic operators; create new folder as 03-01 ArithmeticOperators in src folder of the workspace and create arithmetic_op.go file and type the following code.
Following is the output of above example.
- Commit and push changes to GitHub.
$ git add .
$ git commit -m "03-01 ArithmeticOperators"
$ git push origin master
Assignment Operators
- Assignment operators are used to assign values to variables.
- Following is the list of assignment operators.
-
Create 03-02 AssignmentOperators folder in src folder and add a file assignment_op.go and type the following example.
Commit changes to GitHub
$ git add .
$ git commit -m "03-02 AssignmentOperators"
$ git push origin master
Comparison/Relational Operators
- Comparison operators are used to compare two values.
-
The following example demonstrates the usage of comparison operators. Create folder 03-03 ComparisonOperators in src folder and file with the name comparison_op.go
Commit changes to GitHub.
$ git add .
$ git commit -m "03-03 ComparisonOperators"
$ git push origin master
Logical Operators
- Logical operators are used for operations on Boolean values within the logical expressions.
-
Letβs create a folder 03-04 LogicalOperators in src folder of your workspace and then create file logical_op.go
Commit changes to GitHub.
$ git add .
$ git commit -m "03-04 LogicalOperators"
$ git push origin master
Bitwise Operators
- Bitwise operators work on bits and perform bit-by-bit operation.
- Following is the list of bitwise operators supported by Go.
- To demonstrate the usage of bitwise operators create folder 03-05 BitwiseOperators and file bitwise_op.go
Finally commit Changes to GitHub.
$ git add .
$ git commit -m "03-05 BitwiseOperators"
$ git push origin master
Operators Precedence
- Operator precedence determines the grouping of terms in an expression.
- This affects how an expression is evaluated.
- The following table lists Go's operator precedence level, starting with the highest.
Top comments (0)