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
Server Driven Compose With Firebase
skydoves
0
410
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
1.1k
WEBエンジニア向けAI活用入門
sutetotanuki
0
310
CSC509 Lecture 08
javiergs
PRO
0
110
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.5k
Identifying User Idenity
moro
6
8.3k
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
110
色々なIaCツールを実際に触って比較してみる
iriikeita
0
290
EventSourcingの理想と現実
wenas
6
2.1k
Piniaの現状と今後
waka292
5
1.5k
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8k
How to Ace a Technical Interview
jacobian
275
23k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
GitHub's CSS Performance
jonrohan
1030
460k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Why Our Code Smells
bkeepers
PRO
334
57k
Agile that works and the tools we love
rasmusluckow
327
21k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Git: the NoSQL Database
bkeepers
PRO
426
64k
The Invisible Side of Design
smashingmag
297
50k
Code Reviewing Like a Champion
maltzj
519
39k
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] ߞߜ
ࡏ ࡏ пӍӌҿӗ ҺӑӍӏӍӅ ӊҿӈӗӄӄ ߞߤ