2
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?

【C言語】中学英語で理解する * と &【ポインタ入門】

Last updated at Posted at 2025-09-13

本記事の内容

C言語のポインタにはとても苦労しました。
私の場合、その原因は2つの記号 *& を十分に理解できていなかったことにあります。
しかし、中学校で習うレベルの英語に置き換えて考えてみると、とても理解しやすくなりました。
あくまでざっくりとした解説になります。
正確さに欠ける部分があれば、ぜひコメントでご指摘いただけると幸いです。

ポインタとは

ポインタは別の変数のメモリーアドレス(場所)を保存する変数です。

* の2つの使い方

* は宣言の時とその他で意味が異なります

1. 宣言の時

int *ptr;

ptr(適当においた変数名) が「int型の変数を指すポインタ型」であることを宣言しています。

int* ptr;

このような書き方でも同じ意味になります。
こちらの方が、変数ptrint型へのポインタ型(int*)であると直感的に理解しやすいです。
ただし、複数の変数を宣言する際には注意が必要です。例えば、

int* a, b;

と書くと、aint*(ポインタ)ですが、b は単なる int です。

2. 宣言ではない時(デリファレンス)

*ptr
  • 宣言ではない時、*ポインタ型の変数の前に付きます。
  • ptr(ポインタ型変数) が指しているアドレスにある「値」にアクセスします。これを逆参照(dereference)といいます。
  • *"the value of" と置き換えることができます。*ptr は ”the value of ptr"ということです。(わかりやすい!)

&:変数のアドレスを取得する演算子

int an_integer;
&an_integer
  • &an_integeran_integer(適当においた変数名) のアドレスを取得します。
  • &"the address of" と置き換えることができます。&an_integer は ”the address of an_integer"ということです。(わかりやすい!)

ポインタを使った操作の例

int an_integer = 100; // int型変数の宣言と初期化
int *integer_address = &an_integer; // ポインタ型変数の宣言と初期化
// &an_integer: the address of an_integer

*integer_address = 5;
// *integer_address: the value of integer_address

この結果、an_integer の値は 100 から 5 に変化します。

まとめ

  • *:
    • 宣言の時は、「ポインタ型である」ことを示す
    • 宣言ではない時、ポインタ型変数の前に付いて、"the value of" と置き換えられる(逆参照)
  • &: "the address of" と置き換えられる

参考

2
0
3

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
2
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?