0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Go 言語を学ぶAdvent Calendar 2023

Day 5

【Go言語】ポインタ

Posted at

ポインタとは

値のメモリアドレスを扱う機能のこと。
変数がメモリ上のどこに格納されているかを示すために使用する。

使い方

ポインタの宣言* +
アドレスの取得&演算子
値の参照*演算子

サンプルコード

package main

import "fmt"

func main() {
	var x int = 1
	// xのアドレスをpに割り当てる
	var p *int = &x
	// pが指すアドレスの値を出力する
	fmt.Println(*p) // 1

	// pが指すアドレスの値を変更する
	*p = 2
	fmt.Println(x) // 2
}

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?