[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-go-pointers-memory-management-all--*":3,"academy-blog-translations-76y8utxx73a208l":79},{"data":4,"page":67,"perPage":67,"totalItems":67,"totalPages":67},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":73,"keywords":74,"locale":49,"published_at":75,"scheduled_at":13,"school_blog":71,"short_description":76,"slug":77,"status":69,"title":6,"updated":78,"updated_by":13,"views":72},"EP.6 Go and Pointers - Mastering Memory Management!","sclblg987654321","school_blog_translations","\u003Cp>\u003Cspan style=\"font-size:20px;\">\u003Cstrong>Go and Pointers - Mastering Memory Management!\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Have you ever wondered how programs manage data in memory? Pointers in Go allow you to access and modify values directly through memory addresses.\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>What is a Pointer?\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>In Go, a Pointer is a variable that holds the memory address of a value or another variable. It enables us to access and modify values directly through memory.\u003C\u002Fp>\u003Cp>Example:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">package main\r\n\r\nimport \"fmt\"\r\n\r\nfunc main() {\r\n    x := 10\r\n    ptr := &amp;x \u002F\u002F เก็บที่อยู่ของตัวแปร x\r\n    fmt.Println(\"Address of x:\", ptr) \u002F\u002F แสดงที่อยู่หน่วยความจำ\r\n    fmt.Println(\"Value of x:\", *ptr)  \u002F\u002F ดึงค่า x ผ่าน pointer\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Using Pointers in Functions\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Functions can receive values by reference through Pointers, allowing you to directly modify the original variable's value:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func changeValue(num *int) {\r\n    *num = 100\r\n}\r\n\r\nfunc main() {\r\n    x := 10\r\n    changeValue(&amp;x)\r\n    fmt.Println(\"Updated value of x:\", x) \u002F\u002F Output: 100\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Memory Management in Go\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>Go has a Garbage Collector that automatically manages memory. However, understanding how to use Pointers will help you write efficient programs and avoid unnecessary memory usage.\u003C\u002Fp>\u003Cp>\u003Cspan style=\"font-size:18px;\">\u003Cstrong>Nil Pointer and Pointer Checking\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp>A Pointer that does not point to any variable will have a value of nil:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">var ptr *int\r\nif ptr == nil {\r\n    fmt.Println(\"Pointer is nil\")\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>You can try creating a function that uses a Pointer to swap the values of two variables.\u003C\u002Fp>\u003Cp>Example:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">func swap(a, b *int) {\r\n    temp := *a\r\n    *a = *b\r\n    *b = temp\r\n}\r\n\r\nfunc main() {\r\n    x, y := 1, 2\r\n    swap(&amp;x, &amp;y)\r\n    fmt.Println(\"x:\", x, \"y:\", y) \u002F\u002F Output: x: 2 y: 1\r\n}\r\u003C\u002Fcode>\u003C\u002Fpre>","12_11zon_26wbtlrq5h.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Feo5n6thv00608jy\u002F12_11zon_26wbtlrq5h.webp","2026-03-04 08:34:18.154Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:32:51.346Z","tmzmy6jyz1n35rr","Go Programming","2026-04-10 16:08:01.434Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:34:17.826Z","v52y92wzlfib78r","nil Pointer","2026-04-10 16:08:11.531Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:26:33.331Z","gvourvknzn2n91h","Memory Management","2026-04-10 16:07:30.965Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:26:32.195Z","3lpkahsesypeohl","Pointers","2026-04-10 16:07:30.526Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":54,"collectionId":55,"collectionName":56,"expand":57,"id":71,"views":72},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":66,"priority":67,"publish_at":68,"scheduled_at":13,"status":69,"updated":70,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":66,"th":66},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","76y8utxx73a208l",212,"eo5n6thv00608jy",[20,25,30,35,40],"2025-01-22 05:01:39.665Z","Learn how to declare and use Pointers in Go, along with passing variables into functions by reference and checking for nil Pointers.","go-pointers-memory-management","2026-04-25 02:47:30.932Z",{"en":77}]