More about operators and boolean in go

M

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

Relational Operators

Go uses this boolean in many areas. For example to ask whether one is greater than the other.

Note the == not =

logical operators

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.

Bitwise operators

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?

(Image source: wikipedia)

You can learn more about this here: https://en.wikipedia.org/wiki/Bitwise_operation

Assignment operators

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.

Miscellaneous Operators

We have other operators like ?:, sizeof, *, etc.

But I think they all deserve a separate article.

Hope you guys liked it. Bye

About the author

vigneshwar

1 comment

Leave a Reply

  • Just writing this comment to let you know that I am following this series and golang series on Hitesh’s sir channel. Thanks for this blog post, it helps me a lot in getting myself started in golang.

By vigneshwar

Most common tags

%d bloggers like this: