Found 1082 Articles for Go Programming

Golang program to replace elements in a slice

Akhil Sharma
Updated on 17-Jan-2023 12:27:30

3K+ Views

In this tutorial, , we will grasp how to replace elements in a slice using different set of examples. A slice is a dynamic array which means that its value is not fixed like array. The output will be printed on the screen using fmt.Println() function. Let’s see how it can be implemented with crystal-clear examples. Method 1: Using built-in copy function In this method, we will use the built-in function copy to replace elements in slice which means at the place of original element and new element will be placed. The built-in functions shorten the code and easily solve ... Read More

Golang program to print a slice

Akhil Sharma
Updated on 17-Jan-2023 12:25:09

2K+ Views

In this tutorial, we will learn different methods to print a slice. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s understand this basic concept using different set of examples and algorithms based upon them. Method 1: Using make function In this method, we will create a slice with the help of make function and ... Read More

Golang program to reverse a slice

Akhil Sharma
Updated on 17-Jan-2023 12:19:09

3K+ Views

In this tutorial, we will learn how to reverse a slice using variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of ... Read More

Golang program to search an element in the slice

Akhil Sharma
Updated on 17-Jan-2023 13:08:47

3K+ Views

In this tutorial, we will grasp how to search an element in slice using different set of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument ... Read More

Golang program to remove an element from a slice

Akhil Sharma
Updated on 17-Jan-2023 12:03:48

818 Views

In this tutorial, we will learn how to remove an element from a slice using variety of examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Syntax func copy(dst, str[] type) int The copy function in go language is used to copy the values of ... Read More

Golang program to find the largest element in a slice

Akhil Sharma
Updated on 17-Jan-2023 11:57:09

922 Views

In this tutorial, we will inculcate how to find the largest element in a slice using some examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Method 1: Using a user-defined function and append() function In this method, we will see how to find the largest element ... Read More

Golang program to add elements to a slice

Akhil Sharma
Updated on 17-Jan-2023 11:42:47

768 Views

In this tutorial, we will learn how to add elements to a slice using different examples. A slice is a sequence of elements just like an array. An array is a fixed sequence of elements whereas slice is a dynamic array which means its value is not fixed and can be changed. Slices are more efficient and faster than arrays moreover they are passed by reference instead by value. Let’s go through the example to understand things. Method 1: Using append function with strings In this method, we will use append function to add string elements to the slice. ... Read More

How to check whether a number is Positive or Negative in Golang?

Aman Sharma
Updated on 11-Jan-2023 17:29:03

1K+ Views

In this tutorial, we will learn how to check whether the number is positive or negative. This tutorial includes two ways to achieve this by using the built-in function Signbit() present in the math library. Another way is to use the relation operators using which we can compare a number with zero and predict whether the number is positive or not. Method 1: Using Signbit() function In this example, we are going to use the built-in function Signbit() present in the math library to check whether the number is positive or negative. Syntax Signbit() is a function in math library ... Read More

How to create a Function with Arguments and a return value in Golang?

Aman Sharma
Updated on 11-Jan-2023 17:26:30

673 Views

This tutorial will teach us how to create a function with arguments and a return value. This tutorial involves a gist about the function, and syntax for the function with an argument and a return type in Golang, then last we will see two different examples of a function with arguments and with a return type. In one example we will return the sum of two numbers and in the other one, we will return the area of the circle. Functions in the Programming language. Let us first see what function is. The function is a subset of a program ... Read More

How to create a Function with Arguments but without a return value in Golang?

Aman Sharma
Updated on 17-Jan-2023 10:44:33

244 Views

This tutorial will teach us how to create a function with arguments but without a return value. This tutorial involves a gist about the function, and syntax for the function with argument and without return type in Golang, then last we will see two different examples of a function with arguments but without a return type. In the first example, we are going to print the argument passed in the function with the respective statement. In the other example, we are going to add the numbers passed as arguments and print the sum in the same function. Function with argument ... Read More

Advertisements