×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

What is the default value of a structure in Go language?

Here, we will learn about the structure variable and the default value of the structure variable in Golang.
Submitted by IncludeHelp, on October 03, 2021

A structure is a collection of primitive data types or even other structures and they inherit the default values of the types they are made out of. The default value of a structure (struct) in the Go programming language is the default value of its members.

Example:

// Golang program to demonstrate the
// default value of a structure variable

package main

import "fmt"

type Person struct {
	Name string
	Age  int
	Perc float32
}

func main() {
	var P Person

	fmt.Printf("Default value: %v\n", P)
}

Output:

Default value: { 0 0}

Golang FAQ »



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.