{"id":9870,"date":"2022-09-02T08:17:26","date_gmt":"2022-09-02T08:17:26","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=9870"},"modified":"2024-04-15T10:20:02","modified_gmt":"2024-04-15T10:20:02","slug":"structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/","title":{"rendered":"Structure in Golang"},"content":{"rendered":"<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;A comprehensive guide to data structures in Go&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:513,&quot;3&quot;:{&quot;1&quot;:0},&quot;12&quot;:0}\">A comprehensive guide to data structures in Go<\/span><\/h2>\n<p>Data structures play a fundamental role in computer science and programming by providing efficient ways to organize and manipulate data. In Go (or Golang), a statically typed language designed for simplicity and efficiency, data structures are essential for building robust and scalable applications.<\/p>\n<p>Common data structures in Go include arrays, slices, maps, structs, and pointers. Arrays in Go are fix-size sequences of elements with a specific type, while slices are dynamic, resizable views of arrays. Maps are hash tables used for key-value pair storage, providing efficient lookup, insertion, and deletion operations. Structs allow developers to define custom composite data types by grouping together named fields of different types. Pointers in Go are variables that store memory addresses, enabling efficient memory management and indirect access to data.<\/p>\n<p>Understanding data structures in Go is crucial for writing efficient and idiomatic code. Developers should be familiar with the characteristics, operations, and trade-offs of each data structure to choose the most suitable one for specific use cases. Mastery of data structures empowers developers to design elegant and performant solutions to complex problems in Go programming.A comprehensive guide to data structures in Go.<\/p>\n<ul>\n<li style=\"background: white; vertical-align: baseline;\">\n<h4><span lang=\"EN-IN\" style=\"letter-spacing: .1pt;\">A structure <\/span><span lang=\"EN-IN\" style=\"color: black; background: white;\">is a collection of data fields with <a href=\"https:\/\/prwatech.in\/blog\/go-lang\/installation-of-go-windows\/\">declare<\/a> data <a href=\"https:\/\/go.dev\/\">types<\/a>. Golang can declare and create its data types by combining one or more types, including both built-in and user-defined types.<\/span><\/h4>\n<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\n\r\ntype student struct {\r\n    Name    string\r\n    class   string\r\n    Roll_No int\r\n    Marks   int\r\n}\r\n\r\nfunc main() {\r\n    var s1 = student{\"Sandeep\", \"X\", 2001, 98}\r\n    var s2 student\r\n    s2.Name = \"Sonu\"\r\n    s2.class = \"IX\"\r\n    s2.Roll_No = 2039\r\n    s2.Marks = 56\r\n    fmt.Println(s1)\r\n    fmt.Println(s2)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">PS C:\\GO_Language\\Structure&gt; go run structure.go\r\n{Sandeep X 2001 98}\r\n{Sonu IX 2039 56}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>Accessing Structure members<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\nimport \"fmt\"\r\ntype Books struct {\r\n    title   string\r\n    author string\r\n    subject string\r\n    book-id int\r\n}\r\nfunc main() {\r\n    var Book1 Books\r\n    var Book2 Books\r\n    Book1.title = \"Go Programming\"\r\n    Book1.author = \"Kreston\"\r\n    Book1.subject = \"Go programming tutorial\"\r\n    Book1.book-id = 398312389\r\n\r\n    Book2.title = \"Python Programming\"\r\n    Book2.author = \"Hazera Ali\"\r\n    Book2.subject = \"Python Programming tutorial\"\r\n    Book2.book-id = 392342334\r\n\r\n    fmt.Printf(\"Book 1 Title :%s\\n\", Book1.title)\r\n    fmt.Printf(\"Book 1 author :%s\\n\", Book1.author)\r\n    fmt.Printf(\"Book 1 subject :%s\\n\", Book1.subject)\r\n    fmt.Printf(\"Book 1 book id :%s\\n\", Book1.book-id)\r\n\r\n    fmt.Printf(\"Book 2 Title :%s\\n\", Book2.title)\r\n    fmt.Printf(\"Book 2 author :%s\\n\", Book2.author)\r\n    fmt.Printf(\"Book 2 subject :%s\\n\", Book2.subject)\r\n    fmt.Printf(\"Book 2 book id :\", Book2.book-id)\r\n}\r\n<\/pre>\n<p>Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\Structure&gt; go run structure1.go\r\nBook 1 Title :Go Programing\r\nBook 1 author :Kriston\r\nBook 1 subject :Go programming tutorial\r\nBook 1 book id :%!s(int=398312389)\r\nBook 2 Title :Python Programming\r\nBook 2 author :HZara Ali\r\nBook 2 subject :Python programming tutorial\r\nBook 2 book id :%!(EXTRA int=392342334)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>Golang program to illustrate the pointer to struct<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">package main\r\n\r\nimport \"fmt\"\r\n\r\n\/\/ defining a structure\r\ntype Employee struct {\r\n    fName, lName string\r\n    age, salary  int\r\n}\r\n\r\nfunc main() {\r\n\r\n    \/\/ passing the address of struct variable\r\n    \/\/ emp is a pointer to the Employee struct\r\n    emp := &amp;Employee{\"Sandeep \", \"Sharma\", 23, 10000}\r\n    emp2 := &amp;Employee{\"GuruDatt\", \"Shet\", 40, 60000}\r\n\r\n    \/\/ (*emp).firstName is the syntax to access\r\n    \/\/ the firstName field of the emp8 struct\r\n    fmt.Println(\"First Name:\", (*emp).fName)\r\n    fmt.Println(\"Age:\", (*emp).age)\r\n\r\n    fmt.Println(\"Last Name:\", (*emp2).lName)\r\n    fmt.Println(\"Age:\", (*emp2).age)\r\n}\r\n<\/pre>\n<p>check Output :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">PS C:\\GO_Language\\Structure&gt; go run structure3.go\r\nFirst Name: Sandeep \r\nAge: 23\r\nLast Name: Shet\r\nAge: 40\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A comprehensive guide to data structures in Go Data structures play a fundamental role in computer science and programming by providing efficient ways to organize and manipulate data. In Go (or Golang), a statically typed language designed for simplicity and efficiency, data structures are essential for building robust and scalable applications. Common data structures in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[666,1707],"tags":[2035,2034,1590,2033,1589],"class_list":["post-9870","post","type-post","status-publish","format-standard","hentry","category-go-lang","category-golang-modules","tag-a-comprehensive-guide-to-data-structures-in-go","tag-declaring-and-creating-struct-data-type","tag-pointer-in-struct","tag-struct-in-golang","tag-structure-in-go-lang"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A comprehensive guide to data structures in Go - Prwatech<\/title>\n<meta name=\"description\" content=\"Master A Comprehensive Guide to Data Structures in Go - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A comprehensive guide to data structures in Go - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master A Comprehensive Guide to Data Structures in Go - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-02T08:17:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-15T10:20:02+00:00\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/\",\"url\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/\",\"name\":\"A comprehensive guide to data structures in Go - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2022-09-02T08:17:26+00:00\",\"dateModified\":\"2024-04-15T10:20:02+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master A Comprehensive Guide to Data Structures in Go - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Structure in Golang\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A comprehensive guide to data structures in Go - Prwatech","description":"Master A Comprehensive Guide to Data Structures in Go - Dive deep with our expert instructors and comprehensive curriculum.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"A comprehensive guide to data structures in Go - Prwatech","og_description":"Master A Comprehensive Guide to Data Structures in Go - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2022-09-02T08:17:26+00:00","article_modified_time":"2024-04-15T10:20:02+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/","url":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/","name":"A comprehensive guide to data structures in Go - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2022-09-02T08:17:26+00:00","dateModified":"2024-04-15T10:20:02+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master A Comprehensive Guide to Data Structures in Go - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/go-lang\/structure-in-golang-2-a-comprehensive-guide-to-data-structures-in-go\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Structure in Golang"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=9870"}],"version-history":[{"count":5,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9870\/revisions"}],"predecessor-version":[{"id":11535,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9870\/revisions\/11535"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=9870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=9870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=9870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}