Function arguments in Golang
Go supports two main ways to pass arguments: Pass by Value and Pass by Reference. Go uses pass by value by default.
Hello, World! is the first basic program in any programming language. You can write this first program in Golang by following the steps below.
First, open the Go compiler. In the Go language, programs are saved with the .go extension and are UTF-8 text files.
Now, first add the main package to your program:
package main
Every program must start with a package declaration . In Go, packages are used to organize and reuse code. In Go , there are two types of programs available, executables and libraries. Executables are programs that can be run directly from the terminal. Libraries are program packages that we can reuse in our programs. Here, the main package tells the compiler that the package should be compiled into an executable program, not a shared library. This is the starting point of the program and also contains the main function .
After adding main package import “fmt” package to your program:
import(
"fmt"
)
Here, import keyword is used to import packages into the program and fmt package is used to implement formatted Input/Output using functions.
Now write code in main function to print hello world in Go language:
func main() {
fmt.Println("!... Hello World ...!")
}
In the above lines of code, we have:
For example:
// Chương trình Go đầu tiên
package main
import "fmt";
// Hàm chính
func main() {
fmt.Println("!... Hello World ...!")
}
Result:
!... Hello World ...!
How to run Golang program
To run a Go program, you need a Go compiler. Once you have a Go compiler, first create a program and save your program with the .go extension , for example, first.go . Now we run this first.go file in the go compiler using the following command, i.e.:
$ go run first.go
Go supports two main ways to pass arguments: Pass by Value and Pass by Reference. Go uses pass by value by default.
In Go language, you are allowed to return multiple values from a function, using the return statement. In other words, in a function, a return statement can return multiple values.
Golang like most other programming languages has switch statement. Here is how to use switch statement in Golang.
In this article, we will learn how to use default case to avoid deadlock. But first, we will learn what is deadlock case when using select command in Golang?
Anonymous structs in Golang are temporary structures with no names used for one-time purposes, while anonymous fields allow embedding of unnamed fields.
What is Rune in Golang? How to use Rune in Golang? This article will give you the answer.
Operators allow us to perform different types of operations on operands. In Go language, operators can be classified based on their different functions.
_(underscore) in Golang is called Blank Identifier. Identifier is a user-defined name of program elements used for identification purposes.
Golang can be easily installed on Windows. Here is a step-by-step guide to install Golang on Windows.
Golang allows creating two or more methods with the same name in the same package, but the receivers of these methods must be of different types.
In Go, functions are blocks of code that perform specific tasks, which can be reused throughout the program to save memory, improve readability, and save time.
The scope of a variable in Golang determines which part of the program the variable is accessible to. In Go, all identifiers have a lexical scope that is determined at compile time.
What conditional statements does Golang have? How to use conditional statements in Go programming? Let's find out together!
The short variable declaration operator (:=) in Golang is used to create variables with a proper name and initial value. Here is what you need to know about the short variable declaration operator in Golang.
After a few days of confusion, Google has officially confirmed the issue with both the second-generation Chromecast and Chromecast Audio.
Unfortunately, it seems that bad guys have found a vulnerability in Firefox and are actively using it right now.
Canva supports you with many tools to change your design very professionally. For example, you can change the design color on Cava with just a simple click.
Reference citations in Google Docs make it easier for readers to refer to the content in the document. And in the process of adding citations, users can change them to suit the document.
WhatsApp accounts are locked for many reasons, it could be because you did something that caused Meta to lock your WhatsApp account or because of Meta.
With GIMP, often jokingly referred to as the free version of Photoshop, users can easily remove objects in the background of images with just a few tools. This technique requires a little patience to get the best results.
FC Mobile Code contains many rewards such as FC Point, player package, diamond package... Below we have compiled the latest FC Mobile giftcodes along with how to redeem codes to receive rewards.
AFK Journey Code will help players have a smoother and easier start in their journey.
Code Xsamkok Super Energy Three Kingdoms gives players a series of rewards when exchanging codes.
Convert numbers to words in Excel, convert amounts to words with Excel versions from 2003 to 2016, Excel is free like WPS Office, no need to install add-ins, supports both 32-bit and 64-bit versions.
What is the percentage function in Google Sheets? How to calculate percentage in Google Sheets? Let's find out with Quantrimang.com!
Autodesk AutoCAD 2020 has a free download program for those who are students, students or teachers with copyrighted software. Users only need to use the confirmation document and that's it.
The idea behind Samsung's system-wide internal search feature is to help users find everything they need on their device from a single area, with simple, quick operations.
When you turn this feature off, only registered accounts can use your Chromebook. It's super simple to do.
Mufasa: The Lion King has officially premiered worldwide. Is Mufasa: The Lion King worth your money to see in theaters?