Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
•
Sicherheitslücken (CVE)IT Security News Hourly Summary 2026-09-29 11h : 7 posts(29.09.2026 um 11:00 Uhr)
•
IT Security NachrichtenSeptember 2026 Cyber Attacks Timeline(29.09.2026 um 11:01 Uhr)
•••
IT Security NachrichtenCloudflare’s EmDash 1.0 makes sandboxed plugins ask for access first(29.09.2026 um 11:03 Uhr)
•
IT Security NachrichtenEngineering velocity is a competitive advantage in modern cybersecurity(29.09.2026 um 11:00 Uhr)
•
Sicherheitslücken (CVE)Kiteworks patches critical flaw, brings customer systems online(29.09.2026 um 11:04 Uhr)
•
IT Security NachrichtenGroßrazzia gegen Mogel-Handy-Ring: 300 Millionen Euro Schaden(29.09.2026 um 11:14 Uhr)
•
Malware / Trojaner / VirenMalware-Schutz auf QNAP-NAS richtig steuern(29.09.2026 um 11:00 Uhr)
••
Sicherheitslücken (CVE)IT Security News Hourly Summary 2026-09-29 11h : 7 posts(29.09.2026 um 11:00 Uhr)
•
IT Security NachrichtenSeptember 2026 Cyber Attacks Timeline(29.09.2026 um 11:01 Uhr)
•••
IT Security NachrichtenCloudflare’s EmDash 1.0 makes sandboxed plugins ask for access first(29.09.2026 um 11:03 Uhr)
•
IT Security NachrichtenEngineering velocity is a competitive advantage in modern cybersecurity(29.09.2026 um 11:00 Uhr)
•
Sicherheitslücken (CVE)Kiteworks patches critical flaw, brings customer systems online(29.09.2026 um 11:04 Uhr)
•
IT Security NachrichtenGroßrazzia gegen Mogel-Handy-Ring: 300 Millionen Euro Schaden(29.09.2026 um 11:14 Uhr)
•
Malware / Trojaner / VirenMalware-Schutz auf QNAP-NAS richtig steuern(29.09.2026 um 11:00 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Pointers in Go Explained

If you’re new to Go or programming in general, you may have come across pointers and felt a bit intimidated. I’ve been there! When I first encountered pointers, I saw the ampersand (&) and asterisk (*) symbols and instantly thought, Wha…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

If you’re new to Go or programming in general, you may have come across pointers and felt a bit intimidated. I’ve been there! When I first encountered pointers, I saw the ampersand (&) and asterisk (*) symbols and instantly thought, What is happening here?



In this post, we’re going to break down pointers with a simple analogy and see how they work in Go. By the end, you’ll understand what pointers do and why they’re powerful tools in programming.






What are Pointers?



Imagine you’re looking at a map that shows the addresses of houses. Each house has an address, but that address doesn’t tell you anything about what’s inside the house—only where it’s located. In programming, variables are like those houses: each one has a memory address, where its data is stored.



though bubble with word pointer inside

A pointer holds the address of a variable, not the actual data inside the variable. It’s like writing down the address of a house so you can find it later.





So, What is a Variable?



A variable is the named spot in memory where data is stored. You can think of it as a specific house with a unique address on our map.

We use variables names because they are easy for us to remember, while memory addresses are often n hexadecimal form like 0x564B4.




package main

import "fmt"

func main(){
var balance int = 35
fmt.Println("Age:",age) //Output the value of balance
fmt.Println("Memory Address:", &age)//Output the address of balance
}








  • balance is a variable, that holds the value 35


  • &balance is the memory address of balance. which Go represents as a hexadecimal numbers like 0x50C






Working with Pointers in Go



In Go, you use the ampersand (&) to get the address of a variable, and the asterisk (*) to access the value at that address.






1.Declaring a Pointer



You can create a pointer that points to an address of a variable. Here's how:




package main

import "fmt"

func main() {
balance := 35 // Our variable
balancePtr := &balance // Pointer to the memory address of balance

fmt.Println("Balance:", balance) // 35
fmt.Println("Pointer:", balancePtr) // Memory address of balance (e.g., 0x50C)
fmt.Println("Value at Pointer:", *balancePtr) // 35, value at that address
}






Breakdown:





  • balance := 35 creates an integer variable with a value of 35.


  • balancePtr := &balance creates a pointer balancePtr that holds the address of balance.


  • *balancePtr lets us access the value stored at balancePtr's address, which is 35.






Why Use Pointers?



Pointers allow you to work with data directly in memory, without making copies. This is useful for larger data structures or when modifying data across functions.



Example of a function that modifies a variable's value:




package main

import "fmt"

func updateBalance(balancePtr *int) {
*balancePtr = 40 // Change the value at the address
}

func main() {
balance := 35
fmt.Println("Before:", balance) // 35

updateBalance(&balance) // Pass the address of balance to the function
fmt.Println("After:", balance) // 40, since updateBalance modified the value directly
}






The breakdown:





  • updateBalance takes a pointer balancePtr as a parameter.


  • *balancePtr = 40 changes the value at memory held by balancePtr.

  • In main, when we pass &balance to updateBalance, updateBalance directly changes balance's value without returning anything.






Key Points





  • Pointer store memory addresses, not values.


  • & gives you the address of a variable.


  • * allows you to access the value at an address.


  • Pass by reference: By passing pointers to functions(as parameters), you can modify variables directly without returning them.






The End



Pointers may feel strange at first, but they become second nature with practice. Using pointers efficiently can improve memory usage and program performance.Understanding pointers will make you a stronger Go developer and give you more control over how data flows in your programs.



2 Gopher mascot with words bye bye

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Pointers in Go Explained

Thematisch verwandte Begriffe: Pointers, Explained · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-102240 | A vulnerability was found in Netcore NAP930 0.1.241010.141410. This aff…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag