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
CSC509 Lecture 11
javiergs
PRO
0
180
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Jakarta EE meets AI
ivargrimstad
0
550
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
210
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
The Language of Interfaces
destraynor
154
24k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Six Lessons from altMBA
skipperchong
27
3.5k
Designing for humans not robots
tammielis
250
25k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Happy Clients
brianwarren
98
6.7k
Optimizing for Happiness
mojombo
376
70k
Designing for Performance
lara
604
68k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
RailsConf 2023
tenderlove
29
900
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] ߞߜ
ࡏ ࡏ пӍӌҿӗ ҺӑӍӏӍӅ ӊҿӈӗӄӄ ߞߥ