Overview Like any other variable, a constant will be global within a package if it is declared at the top of a file outside the scope of any function. For example, in…
Author: admin
Constant in inner/outer scope in Go (Golang)
Overview A constant declared within an inner scope having a same name as constant declared in the outer scope will shadow the constant in outer scope. Example Output The above program prints…
Can constant be reassigned after its declaration in Go (Golang)
Overview Constant Variable cannot be reassigned after its declaration as it is constant and its value cannot change. If you try to reassign to a constant variable then it will raise a…
Constant in Go (Golang)
This is the chapter 9 of the golang comprehensive tutorial series. Refer to this link for other chapters of the series – Golang Comprehensive Tutorial Series Next Tutorial – For LoopPrevious Tutorial –Functions Now let’s check…
Create panic by calling panic function in Go (Golang)
Overview Go provides a special function to create a panic. Below is the syntax of the function This function can be called explicitly by the programmer to create a panic. It takes…
Can defer be used inside main function in Go (Golang)
Overview Defer as the name suggests is used to defer the cleanup activities in a function. These cleanup activities will be performed at the end of the function. defer can be used…
Defer and Methods in Go (Golang)
Overview defer statement is also applicable for methods in a similar way it is applicable to functions. Let’s see an example Example In the above program, we do defer file.Close() after opening…
Defer function and Named Return Values in Go (Golang)
Overview In case of named return value in the function, the defer function can read as well as modified those named return values. If the defer function modifies the name return value…
Multiple defer functions in Go (Golang)
Overview There can be two cases of multiple defer functions Multiple Defer function within a particular function Multiple Defer function in different functions Before we see an example for both let’s see…
What happens during panic in Go (Golang)
Overview Let’s understand what happens when panic happens in a program. Imagine a function call from main function to f1 function to f2 function main->f1->f2 Now let’s say that panic happens in…