Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
№ 2017/2. Численные типы данных, массивы, указа...
Search
Основы Программирования
March 02, 2017
Programming
0
440
№ 2017/2. Численные типы данных, массивы, указатели
Лекция о целочисленных и вещественных типах данных, одномерных массивах, указателях.
Основы Программирования
March 02, 2017
Tweet
Share
More Decks by Основы Программирования
See All by Основы Программирования
№ 2018/3. Динамическая память, указатели на функции, символы, строки
nsu_op
0
350
№ 2018/2. Численные типы данных, массивы, указатели
nsu_op
0
400
№ 2017/3. Динамическая память, указатели на функции, символы, строки
nsu_op
0
390
№ 2016/3. Массивы, указатели, память
nsu_op
1
270
№ 2016/2. Представление чисел в памяти
nsu_op
0
560
Other Decks in Programming
See All in Programming
Hotwire or React? ~Reactの録画機能をHotwireに置き換えて得られた知見~ / hotwire_or_react
harunatsujita
9
4.4k
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.8k
Amazon Qを使ってIaCを触ろう!
maruto
0
200
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.8k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
460
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
150
プロジェクト新規参入者のリードタイム短縮の観点から見る、品質の高いコードとアーキテクチャを保つメリット
d_endo
1
1k
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
110
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
2
170
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.6k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
A Tale of Four Properties
chriscoyier
156
23k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
Building Adaptive Systems
keathley
38
2.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Docker and Python
trallard
40
3.1k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Transcript
ࡏ ࡏ фӐӌӍҺӝ ӎӏӍһӏҸӋӋӄӏӍҺҸӌӄӨ сҿӈӗӄӨ ॏ ߞࡈ ߞ ӋҸӏӑҸ ߞߜߝߣ
һࡏ ࡏ http://xkcd.com/571
ࡏ ࡏ кӌҸӈӍӋӐӑҺӍ џ ࡴ бӊҸҾӄӋӄӏ бӊҸҾӄӋӄӏӍҺӄӖ хҸӏӔӄӌҿӌӈӍࡈ ࡄ ҹҸӈҸӊҸҺӏ
ӔӄӃӄӈӄ ыыࡈ ӋҸһӄӐӑӏ ӋҸӑҿӋҸӑӄӈӄ ттыࡈ ࡄ ӎӏӍӔҿӐӐӄӍӌҸӊӛӌӝӅ ӎӏӍһӏҸӋӋӄӐӑ CʾżƚȀɯǞȩɟࡈ ࡄ ӏҿһӒӊӨӏӌӍ ӖҿӋӒࡷӑӍ ӒӖӒ ыыࡈ Яышлࡈ ся ытяࡏ пӍӌӑҸӈӑࡇ ʲȀŏƇǞȒǞɟࡏɔŏɟ˙ȘƚȘǺȩॅǃȒŏǞȀࡏżȩȒ ߞ
ࡏ ࡏ юҿӊӍӖӄӐӊҿӌӌӝҿ ӑӄӎӝ ҾҸӌӌӝӕ ࡏ
ࡏ ࡏ еҺӍӄӖӌҸӨ ӐӄӐӑҿӋҸ ӐӖӄӐӊҿӌӄӨ чҸӋӝӅ ӎӏӍӐӑӍӅ ӋҿӑӍҾ ӃҸӎӄӐӄ ӖӄӐҿӊࡈ
ӄӐӎӍӊӛӃӒӧәӄӅ ӑӍӊӛӈӍ ҾҺҿ ӗӄӔӏӝࡇ ߜ ӄ ߝࡏ ч ӎӍӋӍәӛӧ ȗ ӔӓӉӊӝӊӋ ӋӍӂӌӍ ӃҸӎӄӐҸӑӛ ߞȗ ӖӄӐҿӊࡏ 000ߞ = ߜ, 100ߞ = ߠ, 001ߞ = ߝ, 101ߞ = ߡ, 010ߞ = ߞ, 110ߞ = ߢ, 011ߞ = ߟ, 111ߞ = ߣ. ߠ
ࡏ ࡏ эӄӐӊҸ Һ ӎҸӋӨӑӄ ӈӍӋӎӛӧӑҿӏҸ ߝ ҿҾӋӗ ӐӍӐӑӍӄӑ ӄӃ
ߤ ҿӊӗ ӄ ӋӍӂҿӑ ӈӍҾӄӏӍҺҸӑӛ ߞߤ = ߞߡߢ ӏҸӃӊӄӖӌӝӕ ӖӄӐҿӊࡏ уҸӎӏӄӋҿӏࡈ ӖӄӐӊӍ ߟߟߣ ӈӍҾӄӏӒҿӑӐӨ ӋӄӌӄӋӒӋ ߞ ҹҸӅӑҸӋӄࡇ 00000001 ҹӄӑӝ ߝߡ...ߤ 01010001 ҹӄӑӝ ߣ...ߜ ࡄ ߝ ҹҸӅӑ ߤ ҹӄӑ ӈӍҾӄӏӒҿӑ ߞߡߢ ӖӄӐҿӊࡈ ࡄ ߞ ҹҸӅӑҸ ߝߢ ҹӄӑ ӈӍҾӄӏӒӧӑ ߢߡ ߡߟߢ ӖӄӐҿӊࡈ ࡄ ߠ ҹҸӅӑҸ ߟߞ ҹӄӑҸ ӈӍҾӄӏӒӧӑ ߠ ߞߥߠ ߥߢߣ ߞߥߢ ӖӄӐҿӊࡈ ࡄ ߤ ҹҸӅӑ ߢߠ ҹӄӑҸ ӈӍҾӄӏӒӧӑ ߝߤ ߠߠߢ ߣߠߠ ߜߣߟ ߣߜߥ ߡߡߝ ߢߝߢ ӖӄӐҿӊࡏ ߡ
ࡏ ࡏ юҿӊӍӖӄӐӊҿӌӌӝҿ ӑӄӎӝ Һ + шӄӎ цҸӃӋҿӏࡈ ҹӄӑ тӄӌӄӋӒӋ
тҸӈӐӄӋӒӋ unsigned char ߸ ߰ ߞߡߡ unsigned short ߱߶ ߰ ߢߡ ߡߟߡ unsigned int ߲߳ ߰ ߠ ߞߥߠ ߥߢߣ ߞߥߡ unsigned long long ߶ߴ ߰ ߝߤ,ߠ · ߝߜߝߤ signed char ߸ ߝߞߤ ߝߞߣ short ߱߶ ߟߞ ߣߢߤ ߟߞ ߣߢߣ int ߲߳ ߞ ߝߠߣ ߠߤߟ ߢߠߤ ߞ ߝߠߣ ߠߤߟ ߢߠߣ long long ߶ߴ ߥ,ߞ · ߝߜߝߤ ߥ,ߞ · ߝߜߝߤ ߢ
ࡏ ࡏ чӊӍӂҿӌӄҿ ӗҿӊӝӕ ӖӄӐҿӊ Ӑ ӎҿӏҿӎӍӊӌҿӌӄҿӋ цҸӐӐӋӍӑӏӄӋ ӐӊӍӂҿӌӄҿ ҾҺӒӕ
ߤࡷҹӄӑӌӝӕ ҹҿӃӃӌҸӈӍҺӝӕ ӖӄӐҿӊ ߞߡߜ + ߥ = 1111 1010ߞ + 0000 1001ߞ = . . . + 1111 1010 0000 1001 1 0000 0011 ߤ ҹӄӑ ч ӑӍӖӈӄ ӃӏҿӌӄӨ ӈӍӋӎӛӧӑҿӏҸࡇ ߞߡߜ + ߥ = 0000 0011ߞ = ߟࡏ ߣ
ࡏ ࡏ бӄҾӝ ӎҿӏҿӎӍӊӌҿӌӄӨ ӗҿӊӝӕ ӖӄӐҿӊ аҿӃӃӌҸӈӍҺӝҿ ߤࡷҹӄӑӌӝҿࡇ ࡄ ߞߡߡ
+ ߝ = ߜࡈ ࡄ ߜ ߝ = ߞߡߡࡏ кӌҸӈӍҺӝҿ ߤࡷҹӄӑӌӝҿࡇ ࡄ ߝߞߣ + ߝ = ߝߞߤࡈ ࡄ ߝߞߤ ߝ = ߝߞߣࡏ ߤ
ࡏ ࡏ CɔǞż _ŏǞȀɯ ࡄ ߝߟ ӄӧӌӨ ߞߜߜߥ һࡏ ࡴ
÷ʶǞɾɾƚɟࡇ ӎӍӏӨҾӈӍҺӝӅ ӌӍӋҿӏ ӑҺӄӑӍҺ ӎҿӏҿӎӍӊӌӄӊ ߟߞࡷҹӄӑӌӍҿ ӃӌҸӈӍҺӍҿ ӗҿӊӍҿࡏ ࡄ ߞߞ ӐҿӌӑӨҹӏӨ ߞߜߜߥ һࡏ ࡴ ÷ʶǞɾɾƚɟࡇ ӎӍӏӨҾӈӍҺӝӅ ӌӍӋҿӏ ӑҺӄӑӍҺ ӎҿӏҿӎӍӊӌӄӊ ߟߞࡷҹӄӑӌӍҿ ҹҿӃӃӌҸӈӍҺӍҿ ӗҿӊӍҿࡏ ࡄ ߥ ӔҿҺӏҸӊӨ ߞߜߝߟ һࡏ ࡴ °ɔƚȘëɾɟƚƚɾŏɔࡇ ӎӍӏӨҾӈӍҺӝӅ ӌӍӋҿӏ ӑӍӖҿӈ ӌҸ ӈҸӏӑҿ ӎҿӏҿӎӍӊӌӄӊ ߟߞࡷҹӄӑӌӍҿ ӃӌҸӈӍҺӍҿ ӗҿӊӍҿࡏ ࡄ ߝ ҾҿӈҸҹӏӨ ߞߜߝߠ һࡏ ࡴ Įȩʕ÷ʕųƚࡇ ӈӍӊӄӖҿӐӑҺӍ ӎӏӍӐӋӍӑӏӍҺ ӍҾӌӍһӍ ҺӄҾҿӍ ӎҿӏҿӎӍӊӌӄӊӍ ߟߞࡷҹӄӑӌӍҿ ӃӌҸӈӍҺӍҿ ӗҿӊӍҿࡏ ࡄ ߞߜ ӨӌҺҸӏӨ ߞߜߝߣ һࡏ ࡴ +ȩƇƚࡏȩɟǃࡇ ӄҾҿӌӑӄӔӄӈҸӑӍӏ ӐӑӒҾҿӌӖҿӐӈӄӕ ӏҸҹӍӑ ӎҿӏҿӎӍӊӌӄӊ ߟߞࡷҹӄӑӌӍҿ ҹҿӃӃӌҸӈӍҺӍҿ ӗҿӊӍҿࡏ ߥ
ࡏ ࡏ бҿәҿӐӑҺҿӌӌӝҿ ӑӄӎӝ ҾҸӌӌӝӕ ࡏ
ࡏ ࡏ эӄӐӊҸ Ӑ ӎӊҸҺҸӧәҿӅ ӑӍӖӈӍӅ ʺ = ȑ ·
ųƙ , һҾҿࡇ ࡄ ȑ ࡴ ӑҾӒӗӊӖӖҾ ӃӌҸӖҸәҸӨ ӖҸӐӑӛࡈ ࡄ ų ࡴ ӓӖӒӓӀҾӒӊӅ ӖӗӅӔӅӒӊ ӍҹӝӖӌӍ ߞ ӄӊӄ ߝߜࡈ ࡄ ƙ ࡴ ӨӎӖӔӓӒӅӒӗҾ ӎӍӏӨҾӍӈࡏ ߝߝ
ࡏ ࡏ эӄӐӊҸ Ӑ ӎӊҸҺҸӧәҿӅ ӑӍӖӈӍӅ Һ + шӄӎ тӄӌࡏ
ҸҹӐࡏ ӃӌҸӖҿӌӄҿ тҸӈӐࡏ ҸҹӐࡏ ӃӌҸӖҿӌӄҿ шӍӖӌӍӐӑӛࡈ ҾҿӐࡏ ӃӌҸӈӍҺ float ߝ,ߝߤ · ߝߜ ߟߤ ߟ,ߠߜ · ߝߜߟߤ ߣ double ߞ,ߞߟ · ߝߜ ߟߜߤ ߝ,ߤߜ · ߝߜߟߜߤ ߝߢ ߝߞ
ࡏ ࡏ фӐӍҹҿӌӌӝҿ ӖӄӐӊҸ эӄӐӊҸ ±ߜࡈ ± Ȁȩǃ(ߜ) = ,
ߝ/(+ߜ) = + , ߝ/( ߜ) = . уҿࡷӖӄӐӊҸ ŏࡈ ȩɾ ŏ ʕȒųƚɟࡇ ŏ = ߝ, ߜ/ߜ, ߜ · , / , , ߝߟ
ࡏ ࡏ хӏӍҹӊҿӋӝ Ӑ ӑӍӖӌӍӐӑӛӧ ࡄ фӈӏӒһӊҿӌӄҿࡇ ɾǃ( ) =
ߜ, ɾǃ( /ߞ) = ࡏ ࡄ уҸӈӍӎӊҿӌӄҿ ӍӘӄҹӍӈࡇ ŏ + (ų + ż) = (ŏ + ų) + żࡏ ࡄ хӍӑҿӏӨ ӑӍӖӌӍӐӑӄࡇ ŏ ųࡈ ҿӐӊӄ ŏ ųࡏ ࡄ хӍӑҿӏӨ ӑӍӖӌӍӐӑӄࡇ ŏ + ųࡈ ҿӐӊӄ ŏ ų ӄӊӄ ŏ ųࡏ ࡄ чӏҸҺӌҿӌӄҿ ӖӄӐҿӊࡏ ߝߠ
ࡏ ࡏ тҸӐӐӄҺӝ ࡏ
ࡏ ࡏ фҹӜӨҺӊҿӌӄҿ ӋҸӐӐӄҺҸ тҸӐӐӄҺ ࡴ ӒӎӍӏӨҾӍӖҿӌӌӝӅ ӌҸҹӍӏ ӢӊҿӋҿӌӑӍҺ ӍҾӌӍһӍ
ӑӄӎҸࡏ фҹӜӨҺӊҿӌӄҿ ӋҸӐӐӄҺҸ arrࡈ ӐӍӐӑӍӨәҿһӍ ӄӃ N ӢӊҿӋҿӌӑӍҺ ӎӏӍӄӃҺӍӊӛӌӍһӍ ӑӄӎҸ Tࡇ T arr[N]; һҾҿ N ࡴ ӈӍӌӐӑҸӌӑҸ ҺӏҿӋҿӌӄ ӈӍӋӎӄӊӨӗӄӄࡏ хӏӄӋҿӏ ӍҹӜӨҺӊҿӌӄӨ ӄ ӄӌӄӗӄҸӊӄӃҸӗӄӄ ӋҸӐӐӄҺҸࡇ int xs[4]; // {?, ?, ?, ?} int ys[] = {20, 10}; // {20, 10} int zs[4] = {20, 10}; // {20, 10, 0, 0} ߝߢ
ࡏ ࡏ еӍӐӑӒӎ ӈ ӢӊҿӋҿӌӑҸӋ ӋҸӐӐӄҺҸ T arr[N]ࡇ ࡏ ࡏ
ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ ࡏ 0 ࡏ ࡏ 1 ࡏ ࡏ ࡏ ࡏ ࡊ ࡏ ࡏ ࡏ ࡏ N-1 эӑҿӌӄҿ ӢӊҿӋҿӌӑҸ ӄӃ ӋҸӐӐӄҺҸ ӎӍ ӄӌҾҿӈӐӒ iࡇ T value = arr[i]; кҸӎӄӐӛ ӢӊҿӋҿӌӑҸ Һ ӋҸӐӐӄҺ ӎӍ ӄӌҾҿӈӐӒ iࡇ arr[i] = new_value; ߝߣ
ࡏ ࡏ щӈҸӃҸӑҿӊӄ ࡏ
ࡏ ࡏ щӈҸӃҸӑҿӊӛ ӈҸӈ ҸҾӏҿӐ ࡏ ࡏ ࡏ ߡߝߤ ࡏ
ࡏ ߟߞߜ ࡏ 0x20 ࡏ 0x23 ࡏ 0x40 ࡏ 0x43 int x = 518; int y = 320; int* ptr; // & - взятие адреса // * - разыменование указателя ptr = &x; printf("%p %d\n", ptr, *ptr); // 0x20 518 ptr = &y; printf("%p %d\n", ptr, *ptr); // 0x40 320 ߝߥ
ࡏ ࡏ щӈҸӃҸӑҿӊӛ ӈҸӈ ҸҾӏҿӐ ࡏ ࡏ ࡏ ߡߝߤ ࡏ
ࡏ ߥߥߥ ࡏ 0x20 ࡏ 0x23 ࡏ 0x40 ࡏ 0x43 int x = 518; int y = 320; int* ptr; // & - взятие адреса // * - разыменование указателя ptr = &x; printf("%p %d\n", ptr, *ptr); // 0x20 518 ptr = &y; printf("%p %d\n", ptr, *ptr); // 0x40 320 *ptr = 999; printf("%d %d\n", x, y); // 518 999 ߝߥ
ࡏ ࡏ тҸӐӐӄҺӝ ӄ ӒӈҸӃҸӑҿӊӄ ࡏ ࡏ ࡏ 0x20 ࡏ
a[0] ࡏ ࡏ 0x22 ࡏ a[1] ࡏ ࡏ 0x24 ࡏ a[2] ࡏ ߝߜ ࡏ ߞߜ ࡏ ߟߜ short a[3] = {10, 20, 30}; short* p = &(a[0]); // 0x20 short* p1 = p + 1; // 0x22 short* p2 = p + 2; // 0x24 ߞߜ
ࡏ ࡏ тҸӐӐӄҺӝ ӄ ӒӈҸӃҸӑҿӊӄ ࡏ ࡏ ࡏ 0x20 ࡏ
a[0] ࡏ ࡏ 0x22 ࡏ a[1] ࡏ ࡏ 0x24 ࡏ a[2] ࡏ ߝߜ ࡏ ߞߜߜ ࡏ ߟߜ short a[3] = {10, 20, 30}; short* p = &(a[0]); // 0x20 short* p1 = p + 1; // 0x22 short* p2 = p + 2; // 0x24 *p1 = 200; ߞߜ
ࡏ ࡏ тҸӐӐӄҺӝ ӄ ӒӈҸӃҸӑҿӊӄ ࡏ ࡏ ࡏ 0x20 ࡏ
a[0] ࡏ ࡏ 0x22 ࡏ a[1] ࡏ ࡏ 0x24 ࡏ a[2] ࡏ ߝߜ ࡏ ߞߜߜ ࡏ ߞߟߜ short a[3] = {10, 20, 30}; short* p = &(a[0]); // 0x20 short* p1 = p + 1; // 0x22 short* p2 = p + 2; // 0x24 *p1 = 200; *p2 = *p1 + *p2; ߞߜ
ࡏ ࡏ тҸӐӐӄҺӝ ӄ ӒӈҸӃҸӑҿӊӄ ࡏ ࡏ ࡏ 0x20 ࡏ
a[0] ࡏ ࡏ 0x22 ࡏ a[1] ࡏ ࡏ 0x24 ࡏ a[2] ࡏ ߝߜ ࡏ ߞߜߜ ࡏ ߞߟߜ short a[3] = {10, 20, 30}; short* p = &(a[0]); // 0x20 short* p1 = p + 1; // 0x22 short* p2 = p + 2; // 0x24 *(p+1) = 200; *(p+2) = *(p+1) + *(p+2); ߞߜ
ࡏ ࡏ тҸӐӐӄҺӝ ӄ ӒӈҸӃҸӑҿӊӄ ࡏ ࡏ ࡏ 0x20 ࡏ
a[0] ࡏ ࡏ 0x22 ࡏ a[1] ࡏ ࡏ 0x24 ࡏ a[2] ࡏ ߝߜ ࡏ ߞߜߜ ࡏ ߞߟߜ short a[3] = {10, 20, 30}; short* p = &(a[0]); // 0x20 short* p1 = p + 1; // 0x22 short* p2 = p + 2; // 0x24 p[1] = 200; p[2] = p[1] + p[2]; // *(x + y) == x[y] ߞߜ
ࡏ ࡏ тҸӐӐӄҺӝ ӄ ӒӈҸӃҸӑҿӊӄ ࡏ ࡏ ࡏ 0x20 ࡏ
a[0] ࡏ ࡏ 0x22 ࡏ a[1] ࡏ ࡏ 0x24 ࡏ a[2] ࡏ ߝߜ ࡏ ߞߜߜ ࡏ ߞߟߜ short a[3] = {10, 20, 30}; short* p = &(*(a)); // 0x20 short* p1 = p + 1; // 0x22 short* p2 = p + 2; // 0x24 p[1] = 200; p[2] = p[1] + p[2]; // *(x + y) == x[y] ߞߜ
ࡏ ࡏ тҸӐӐӄҺӝ ӄ ӒӈҸӃҸӑҿӊӄ ࡏ ࡏ ࡏ 0x20 ࡏ
a[0] ࡏ ࡏ 0x22 ࡏ a[1] ࡏ ࡏ 0x24 ࡏ a[2] ࡏ ߝߜ ࡏ ߞߜߜ ࡏ ߞߟߜ short a[3] = {10, 20, 30}; short* p = a; // 0x20 short* p1 = p + 1; // 0x22 short* p2 = p + 2; // 0x24 p[1] = 200; p[2] = p[1] + p[2]; // *(x + y) == x[y] ߞߜ
ࡏ ࡏ пӍӌҿӗ ҺӑӍӏӍӅ ӊҿӈӗӄӄ ߞߥ