Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
基礎情報処理演習(11)ポインタ
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
自然言語処理研究室
November 28, 2013
Programming
7.6k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
基礎情報処理演習(11)ポインタ
自然言語処理研究室
November 28, 2013
More Decks by 自然言語処理研究室
See All by 自然言語処理研究室
データサイエンス14_システム.pdf
jnlp
0
430
データサイエンス13_解析.pdf
jnlp
0
550
データサイエンス12_分類.pdf
jnlp
0
380
データサイエンス11_前処理.pdf
jnlp
0
510
Recurrent neural network based language model
jnlp
0
190
自然言語処理研究室 研究概要(2012年)
jnlp
0
170
自然言語処理研究室 研究概要(2013年)
jnlp
0
130
自然言語処理研究室 研究概要(2014年)
jnlp
0
160
自然言語処理研究室 研究概要(2015年)
jnlp
0
240
Other Decks in Programming
See All in Programming
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
430
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
ChromeでローカルLLM
ryu1013
0
140
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Featured
See All Featured
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
870
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
Building Adaptive Systems
keathley
44
3.2k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
570
Git: the NoSQL Database
bkeepers
PRO
433
67k
Facilitating Awesome Meetings
lara
57
7.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
Typedesign – Prime Four
hannesfritz
42
3.2k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Transcript
基礎情報処理演習 (11) ポインタ 山本和英 長岡技術科学大学 1
ポインタ 変数の住所を入れる変数 アドレス演算子 &x 変数 x の場所 間接演算子 *p ポインタ
p の指す変数の値 ・ アドレスとは「番地」=変数を記憶している場所のこと。 ・ ポインタとはアドレスを記憶した変数のこと。 ・ どこも指さないNULLポインタというものもある。 ・ 配列はポインタを使って書くことができる。 ・ 関数を使う時は、値を渡す方法とアドレスを渡す方法がある。 ポインタまとめ 2
int k = 3; k (int) 3 3
int k = 3; int *p; k (int) 3 p
ポインタ p を作る。 ここの int は、 ポインタが指す変数が int 型という意味。 4
int k = 3; int *p; p = &k; k
(int) 3 p ポインタ p に 編集 k の住所を代入する 5
int k = 3; int *p; p = &k; printf
(“%d”, *p); k (int) 3 p ポインタ p が指す変数(k) の値(*)、つまり3が表示される。 6
ポインタの作成 int* s; または int *s; ・ ここの int とは、 s
の指す先が int という意味で、ポインタ s が int という意味ではない。 ・ s の指す変数が double なら、 double *s; となる。 アドレスの代入 s = &t; ・ 変数t の住所(アドレス)を s に入れる。 ・ これによって、s を使って t を 操作できる。 ポインタの使い方 *s = 6; ・ ポインタ s が指す変数 t の値を 6 にする。つまり t = 6; と書くのと 同じ。よって、*s は t の別名と 考えてもよい。 7
配列名はポインタである int w[5]; w は w[0]を指す ポインタである。 配列はポインタ風にも書ける w[2] =
3; *(w+2) = 3; と書いても同じ 関数に配列を渡す goto_sub(&w[0]); goto_sub(w); と書いても同じ。 goto_sub(&w); ではないことに注意! 8
ポインタはいつ使うのか? いろいろありますが、授業では二つ紹介します。 1. 関数に配列を渡したい時 ポインタ一つで配列を渡せるので楽 2. 関数から二つ以上の値を受け取りたい時 受け取りたい変数のポインタを関数に渡せば 関数内でいじれるので便利 9
void function (int n1, int n2, int sum, int diff){
sum = n1 + n2; diff = n1 - n2; } void main(void){ ... a = 10; b = 5; function(a, b, wa, sa); } 動かないプログラム 10 sum と diff は 正しく計算できるが wa と sa には 反映されない
void function (int n1, int n2, int *sum, int *diff){
*sum = n1 + n2; *diff = n1 - n2; } void main(void){ ... a = 10; b = 5; function(a, b, &wa, &sa); } 改良版 11 Wa と sa のアドレスを 関数に渡すことで 変数の値が変更される
void set_number(int *vc, int no, int val){ int i; for
(i = 0; i< no; i++){ *(vc+i) = val; } } main(){ int ary[5]; set_number(ary, 5, 0); } 配列 ary のポインタと 二つの数字を渡す 関数に配列のポインタを渡す例 配列の初期化をする関数 vc[0]~vc[no-1]に val を代入 12 set_number(&ary[0], 5, 0); と書いてもよい vc[i] = val; と書いてもよい
おまけ: そう言えば... scanf_s (“%d”, &k); scanf_s で値を入力する際、&kのように変数名の 前に&をつけていたのは、 scanf_s 関数にkのアドレスを渡していたから
です。こうしないとscanf_s関数の中で変数kの値を 操作(scanf_sの場合は数値を代入)できないため、 k ではなく&kとする必要がありました。 13