Posts

Showing posts with the label Golang

Golang Interview Questions

What is the new function? What is vendor in the go module? Write a producer-consumer program using goroutine. Write a two routine: even and old. The even goroutine should only print even numbers and the odd goroutine will only print odd numbers. The max number will be given as an input parameter. What is the closure function in Golang? How to create it? How to access the shared variable in Golang when multiple goroutines are trying to access it? How to handle race condition? What is the difference between Golang's concurrency with other languages? What is the difference between concurrency and parellism? Which one Golang uses and how? How Golang concurrency is fast.

Identifiers in GO

Image
Introduction: Identifiers in any language are name of variable, function, array, struct etc. The same applicable for GO. There are certain rule and convention for identifier in GO. Rules: 1. Identifier should start with letters or underscore. 2. It can contain numbers but it should not be at the start. Number can place in middle or end of identifier. 3. Identifier are case sensitive. It means variables result and Result are two different variables. 4. Go keywords can not be used as identifier. Go has 25 reserved keywords: 5. Go has some predefined identifier. These are not reserved. You can use them in your program. It sounds weird but all basic datatypes are also predefined datatypes, you can use them as variable name in-fact as all identifiers. Below are the list of predefined identifiers: package main import ("fmt") //import "time" func main() { var int int =10 fmt.Println(int+2) } Even though it is allowed, I personally recommend that...