Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 18 of 51

Golang program to print struct variables

Akhil Sharma
Akhil Sharma
Updated on 04-Apr-2023 1K+ 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, we will create a child struct and further create two fields name and age in it. The field values are set by creating the instance of the struct. In the second example, the field values of the Child struct are set in the instance using shorthand declaration and the field ...

Read More

Golang program to create a module with variables

Akhil Sharma
Akhil Sharma
Updated on 04-Apr-2023 485 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 declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and Output. Step 2 − In the first step, create three variables name, age and address using var keyword and assign these variables the desired values. Step 3 − Then, create a ...

Read More

Golang program to create a class inside the module

Akhil Sharma
Akhil Sharma
Updated on 04-Apr-2023 300 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 the module’s directory. Using Child Struct In this Method, we will write a Golang program to create a class inside the module using child struct, a function createstruct will be created which will be called from another module to print child info. Algorithm Step 1 − Import the package ...

Read More

Golang program to check a hash collection is empty or not

Akhil Sharma
Akhil Sharma
Updated on 03-Apr-2023 342 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 by hashing the key into an index. Hash collections in the form of maps have built-in support in Go. Here, a map is a reference type that is declared by using the map keyword, followed by the key type and value type in the format. Syntax func make ...

Read More

Golang program to remove all items from hash collection

Akhil Sharma
Akhil Sharma
Updated on 03-Apr-2023 404 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 collection using two methods. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. func range(variable) The range function is used to iterate over ...

Read More

Golang program to get the size of the hash collection

Akhil Sharma
Akhil Sharma
Updated on 03-Apr-2023 452 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 this program, we have used two examples to get the size of hash collection. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. func ...

Read More

Golang program to search an item in the hash collection

Akhil Sharma
Akhil Sharma
Updated on 03-Apr-2023 320 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 examples. Syntax func range(variable) The range function is used to iterate over any data type. To use this we first have to write the range keyword followed by the data type to which we want to iterate and as a result the loop will iterate till the last element ...

Read More

Golang program to iterate hash collection and print only values

Akhil Sharma
Akhil Sharma
Updated on 03-Apr-2023 421 Views

In golang we can use hashmap and key functions to iterate hash collection. Hashmap is said to be one of the hash collections. In the hashmap the data is stored in key value pairs as we did below. In this program we will use three methods to iterate the hashmap and print its values. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments func append(slice, element_1, element_2…, element_N) []T The append function is ...

Read More

Golang program to get the current weekday

Akhil Sharma
Akhil Sharma
Updated on 03-Apr-2023 559 Views

In this Go language article, we will write proCurrent weekday implies the current day in the week which can be obtained using numerous methods. In this program we will use three examples to get the current weekday for which time package will be imported in the program, it helps in viewing the time. Syntax func Now() Time The Now() function is defined in time package. this function generates the current local time. To use this function, we have to first import the time package in our program. time.Format() This function belongs to the time package. It is used ...

Read More

Golang program to get current time zone

Akhil Sharma
Akhil Sharma
Updated on 03-Apr-2023 6K+ Views

Golang has internal functions like Now() Time, and other Time functions that can be used for getting the current time zone. Current time zone in Go is a time zone where people reside in and see the same standard time. In a country like India IST is observed throughout the nation. In this program we will discuss how to obtain current time zone using two examples. Syntax func Now() Time The Now() function is defined in time package. this function generates the current local time. To use this function, we have to first import the time package in ...

Read More
Showing 171–180 of 507 articles
« Prev 1 16 17 18 19 20 51 Next »
Advertisements