<目次>
(1) C++のポインタとは?概念や基本的な使い方をご紹介
(1-1) はじめに
(1-2) ポインタとは?
(1) C++のポインタとは?概念や基本的な使い方をご紹介
「ポインタ」は一言で表すと「変数の『メモリ上のアドレス』を保持する変数」です。本記事では、そのポインタの構文や使い方の例などをご紹介いたします。
(1-1) はじめに

string fruit = "Apple"; //# stringの「値(Apple)」を出力 cout << fruit; //# stringの「アドレス(006FFA94)」を出力 cout << &fruit;
(1-2) ポインタとは?

//# 通常の変数定義 string fruit = "Apple"; //# ポインタの定義 //# ポインタの名前:fruit_pt //# ポインタに格納するアドレス:&fruit string* fruit_pt = &fruit; //# 変数の出力 cout << fruit << endl; //# 変数のメモリアドレスの出力 cout << &fruit << endl; //# ポインタが保持するアドレスを出力 cout << fruit_pt << endl; //# ポインタの参照する値を出力 cout << *fruit_pt << endl;

//# 以下はいずれも同じ意味 string* fruit_pt; string *frui_ptt