Akhil Sharma has Published 671 Articles

Golang program to depict use of promoted fields

Akhil Sharma

Akhil Sharma

Updated on 04-Apr-2023 12:05:17

303 Views

In golang, promoted fields are the structs that are embedded inside another structs and their fields can also be accessed the structs in which they are embedded. In this article we are going to understand three different approaches to depict use of promoted filed with and without the help of ... Read More

Golang program to show use of rand package

Akhil Sharma

Akhil Sharma

Updated on 04-Apr-2023 12:02:21

228 Views

In golang, a rand package is used to generate random numbers/characters. Firstly, it seeds with the current time to get the different random Output each time then perform any operation. Syntax rand.Seed(value) Rand.Seed() function is used to generate random numbers. It takes a user input as argument which is ... Read More

Golang program to show scope of variables

Akhil Sharma

Akhil Sharma

Updated on 04-Apr-2023 12:01:20

213 Views

In this article, we will write Go language programs to show scope of global and local variables using pointer approach. Scope is referred to as the accessibility of the piece of code in the program in particular function. Scope can be defined in two ways: globally and locally. Global means ... Read More

Golang program to print struct variables

Akhil Sharma

Akhil Sharma

Updated on 04-Apr-2023 11:59:57

963 Views

In this Golang article, we will write programs to print struct variables. Here, there is no concept of classes, instead of that structs are used to represent a collection of related fields or properties. Using Name of the Field and Shorthand Declaration in the Main Function In this method, ... Read More

Golang program to create a module with variables

Akhil Sharma

Akhil Sharma

Updated on 04-Apr-2023 08:24:15

275 Views

In golang we can create a module with variable using const or var keywords, orelse we can even import the module . A module in Go is a group of packages. It helps in managing the distribution of the package. Algorithm Step 1 − Create a package main and ... Read More

Golang program to create a class inside the module

Akhil Sharma

Akhil Sharma

Updated on 04-Apr-2023 08:23:39

118 Views

In this article we will write a Golang program to create a class inside the module. There are no classes only structs are used in this program which will contain the data fields. A module is a collection of the packages having go.mod file at its root. This file determines ... Read More

Golang program to check a hash collection is empty or not

Akhil Sharma

Akhil Sharma

Updated on 03-Apr-2023 13:54:45

167 Views

In this article, we will write a Go language programs to check a hash collection is empty or not. A hash collection is a data structure that contains key-value pairs in Go (Golang) and enables quick lookups, additions, and deletions. The value that corresponds to the key can be accessed ... Read More

Golang program to remove all items from hash collection

Akhil Sharma

Akhil Sharma

Updated on 03-Apr-2023 13:52:55

194 Views

In Golang we can use delete keyword or empy map to remove all the elements from hash collection. Hashmap is a data structure from hash collection. It is an implementation of hash table which takes O(1) constant time to execute. In this program we will remove all items from hash ... Read More

Golang program to get the size of the hash collection

Akhil Sharma

Akhil Sharma

Updated on 03-Apr-2023 13:52:10

260 Views

In Golang we can use various internal functions or packages like len() function or reflect package, to get the size of the hash collection. A Hash collection contains a hashmap which is generally used to create key:value pairs and on the basis of that it shortens the execution time. In ... Read More

Golang program to search an item in the hash collection

Akhil Sharma

Akhil Sharma

Updated on 03-Apr-2023 13:31:07

171 Views

In this article, we will write Golang programs to search an item in the hash collection. A hashmap is part of hash collections. Here we are building a hashmap as set of key-alue pairs using Golang’s map which is constructed using map literal. We will execute this program using two ... Read More

Advertisements