Skip to main content

QnA

1. What is Golang?

Golang (or) Go is an open-source programming language developed by google. Go is statically types and has a rich set of standard libraries, along with built-in garbage collection. It features a unique concurrency model using goroutines and channels, which allows efficient multi-threaded proccesses. Go widely used in backend development, cloud service and large scale systems.

2. What are the basic data types available in Golang?

  • Boolean: bool
  • Numeric:
    • Integers: int8, int16, int32, int64, uint8, uint16, uint32, uint64, int, uint
    • Floating-point: float32, float64
    • Complex numbers: complex64, complex128
  • Text: string, rune (alias for int32 for representing Unicode code points)

3. What is the difference between int and int32 in Golang?

int is a platform-dependent integer type, this meaning it could be 32 bits or 64 bits depending on the underlying architecture(32 or 64 bit). int32 however is explicitly a 32-bit integer on any platform.

4. Explain the use of rune in Golang.

A rune is an alias for int32 and is used to represent a unicode code point in golang. it allows for characters from various languages, special symbols, and emoji to be handled properly.

5. What is the difference between an array and a slice in Golang?

  • Array: An array is a fixed size, ordered collection of elements of the same type.
  • Slice: An slice is a dynamically sized, ordered collection of elements of the same type. slice are not fixed in size and can grow or shrink as needed.

6. What is the capacity of a slice in Golang, and how does it work?

The capacity of the slice is total space allocated for the slice, starting from its first element. It may be greater than the length and determines how much the slice can grow before needing to reallocate memory. Capacity grows as elements are appended.

7. What is interface?

In Go, Interface is a type that specifies a set of method signatures. It allows different types to satisfy the same interface by implementing those methods, providing a way to achieve polymorphism and flexible , reusable code.

8. What is struct?

In Go, Struct is a composite data type that groups together field with different data types. It's used to represent data structures with named fields, similar to classes in other languages (but without methods).

9. What is maps?

In Go, map is a built-in data type that associates key with value. maps are unordered collections of key-value pairs.

10. What is the purpose of the break statement in Golang?

The break statement is used to terminate the execution of the nearest enclosing loop and the controll is transfered to the code following the loop.

11. How does the continue statement work in Golang?

The continue statement skips the remaining code inside the loop for the current iteration and moves to the next iteration of the loop.

12. What is go routines?

A Go routine is a lightweight thread managed by the Go runtime. Go routines allows concurrent execution of functions in golang. they are cheaper than traditional threads, making it possible to run thousands of go routines concurrently within a single program.

13. What is a channel?

A channel is a built-in data type used for communication between go routines. Channels allows go routine to send and receive data, making it easier to synchronize concurrent operations. Channels are type, meaning they carry a specific type of data.

14. What is a buffered channel in Golang?

A buffered channel is a channel with predefined capacity. It allows sending and receiving without blocking as long as the buffer is not full. When the buffer is full, the sending Go routine will block untill the space is available. You create a buffered channel by passing the buffer size to the make function.

15. What is the purpose of the select statement

The select statement is used to wait on multiple channel operations. It allows a Go routine to wait for multiple channels to become ready for sending or receviving data, and it executes the case that is ready first. If no channels are ready, select will block until one is ready.

16. What is the difference between a "send-only" and a "receive-only" channel in Golang?

  • Send-only channel: chan<- is used to restrict a channel to only sending data.
  • Receive-only channel: <-chan is used to restrict a channel to only receiving data.