Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ ポインタの操作 | ポインタ
C基礎
セクション 6.  3
single

single

bookポインタの操作

メニューを表示するにはスワイプしてください

参照演算子 &間接参照演算子 * を使用して、ポインタを作成し操作できます。

ポインタは intchardouble と同様のデータ型です。 ポインタはアドレスを格納するために設計されており、& 演算子を使ってアドレスを取得できます。 ポインタを宣言するには、* 記号を前置します。

main.c

main.c

copy
123
int* intPointer; // Pointer to an `int` variable double* doublePointer; // Pointer to a `double` variable char* charPointer; // Pointer to a `char` variable

本質的に、ポインタは他のオブジェクトのアドレスを保持する変数です。

main.c

main.c

copy
123
int x = 100; // Variable int* pX; // Pointer to an `int` variable pX = &x; // `pX` now points to `x`
Note
注意

通常、ポインタは指し示すオブジェクト名の先頭に p を付けて命名される。

ポインタをデリファレンスすると、そのポインタが指す変数の値にアクセスする

Main.c

Main.c

copy
12345678910111213
#include <stdio.h> int main() { int x = 22543; // Variable int* pX = &x; // `pX` is pointer to `x` printf("The value of `pX` is %p\n", pX); // Value of pointer `pX` printf("The value of `x` by pointer `pX` is %d\n", *pX); // Pointer dereference return 0; }
Note
注意

*(&variable) == *pVariable

ヌルポインタをデリファレンスしようとすると、コンパイラによってエラーが発生します。

Main.c

Main.c

copy
1234567
#include <stdio.h> int main() { int* pX; printf("x = %p", pX); return 0; }
タスク

スワイプしてコーディングを開始

int ポインタと double ポインタのサイズを判定すること。

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 6.  3
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt