An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. There are many operators in GO
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Miscellaneous Operators
I’ll try to cover them as much as I can.
We already know about Arithmetic operators So I’m not gonna cover them again. Here’s a picture to recall.
Now before talking about other operators I must explain about booleans. So from my previous article I said variable are nothing but holds some value. One value it can hold is Boolean.
A boolean is nothing but True or False.
I can say like
Go uses this boolean in many areas. For example to ask whether one is greater than the other.
Its mostly used to combine relational operations,
&& means and
|| means or
! means not
We’ll use more of this conditional making and looping in the upcoming articles.
So I suppose you guys know that computer works in binary. It knows nothing but 1 or 0.
I won’t explain you explain why binary but I can say that its easy to switch states if there’s only two. And you can think of it as ON or OFF.
Is there a current in this wire or not?
You can learn more about this here: https://en.wikipedia.org/wiki/Bitwise_operation
We already know a assignment operator ‘=’
var a int = 5 here = is a assignment operator.
But there are many assignment operators in GO
+=, -=, *=, /= etc. The idea here is simple.
a += 3 is same as
a = a + 3. Its the same for others assignment operators as well like
a -=3 is same as
a = a - 3.
We have other operators like ?:, sizeof, *, etc.
But I think they all deserve a separate article.
Hope you guys liked it. Bye