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
№ 2018/2. Численные типы данных, массивы, указа...
Search
Основы Программирования
March 01, 2018
Programming
0
400
№ 2018/2. Численные типы данных, массивы, указатели
Лекция о целочисленных и вещественных типах данных, одномерных массивах, указателях.
Основы Программирования
March 01, 2018
Tweet
Share
More Decks by Основы Программирования
See All by Основы Программирования
№ 2018/3. Динамическая память, указатели на функции, символы, строки
nsu_op
0
350
№ 2017/3. Динамическая память, указатели на функции, символы, строки
nsu_op
0
390
№ 2017/2. Численные типы данных, массивы, указатели
nsu_op
0
440
№ 2016/3. Массивы, указатели, память
nsu_op
1
270
№ 2016/2. Представление чисел в памяти
nsu_op
0
560
Other Decks in Programming
See All in Programming
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
イベント駆動で成長して委員会
happymana
1
320
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
初めてDefinitelyTypedにPRを出した話
syumai
0
410
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Featured
See All Featured
Faster Mobile Websites
deanohume
305
30k
A better future with KSS
kneath
238
17k
Statistics for Hackers
jakevdp
796
220k
Practical Orchestrator
shlominoach
186
10k
The Language of Interfaces
destraynor
154
24k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Six Lessons from altMBA
skipperchong
27
3.5k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
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] ߞߜ
ࡏ ࡏ пӍӌҿӗ ҺӑӍӏӍӅ ӊҿӈӗӄӄ ߞߤ