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
C Lecture 2013.09.19
Search
masawada
September 19, 2013
Technology
0
150
C Lecture 2013.09.19
masawada
September 19, 2013
Tweet
Share
More Decks by masawada
See All by masawada
10年続くサービスのデータを1日未満のメンテナンスウィンドウで安全に移管する
masawada
5
2.1k
よりよいレビュー環境を求めて / A code review odyssey
masawada
0
2.9k
フロントエンドの秩序は保たれているか?
masawada
1
4.1k
Getting Started with ScratchX
masawada
0
670
GyaPC::Asia Tokyo 2015 LT
masawada
0
1.4k
Privileged Apps with Vue.js
masawada
0
160
Chikubeam
masawada
1
1.5k
Git講習 2014.04.15
masawada
1
310
Hack U at UEC 2014.03.27
masawada
0
1.5k
Other Decks in Technology
See All in Technology
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
2
2.1k
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
270
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
420
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
160
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
180
CustomCopを使ってMongoidのコーディングルールを整えてみた
jinoketani
0
220
kargoの魅力について伝える
magisystem0408
0
200
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Raft: Consensus for Rubyists
vanstee
137
6.7k
It's Worth the Effort
3n
183
28k
Designing for humans not robots
tammielis
250
25k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Optimising Largest Contentful Paint
csswizardry
33
3k
Optimizing for Happiness
mojombo
376
70k
Music & Morning Musume
bryan
46
6.2k
Faster Mobile Websites
deanohume
305
30k
Practical Orchestrator
shlominoach
186
10k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Transcript
ϓϩάϥϛϯάߨश 2013.09.19 by @masawada, @alstamber
Έͳ͞Μ ͓Α͏͍͟͝·͢
ߨࢣ
masawada
alstamber
ΑΖ͓͘͠ئ͍͠·͢
None
ॾ࿈བྷ
• ձ͕12:00·Ͱ͔͑͠·ͤΜ • MMAͷΠϕϯτͰͳ͍ͨΊڭࣨͱΕͣ • ۭ͍ͯͨΒ13:00-15:00͕ͱΕ·͢ • னٳܜΛ12:00-13:00Ͱ͞Έ·͢
• ৯ਆʹ͍͖·͢(ଟ) • ॏཁͳ෦12:00·ͰʹऴΘΒͤ·͢ • 13:00͔ΒΛղ͖·͢ • ͍ΘΏΔԋश • ్தୀࣨՄͰ͢
• શһ͍ͳ͘ͳͬͨΒΊ·͢ • ॾҙ͍Ͱ͢Ͷ • ͜Μͳײ͡ͰਐΊ·͢ • Θ͔Βͳ͍͜ͱ͋ͬͨΒਵ࣭࣌Λ ͱ͍ͯͩ͘͠͞
ߨशͷର
ޙظ͔Β ϓϩάϥϛϯά௨ ͕࢝·Δ
ϓϩάϥϛϯά Α͘Θ͔ΒΜ
͍ͬͯ͏ਓ͚
ܭࢉػ௨ ͱͬͯͳ͍ͻͱ͚
ຊͷత
ޙظͷतۀʹ ͑͏ΔࣝΛ͚ͭΔ
None
ຊͷ͓͠ͳ͕͖ • ϓϩάϥϛϯάͱ • Cͷجૅ • ม • ੍ޚߏจ •
ྻ/ߏମ • ϙΠϯλ • ؔ • ԋश
ϓϩάϥϛϯάͱ
Scratch
͜Ε ϓϩάϥϛϯά
ͻͱͱ͓Γͷཧղ
•ม/ྻ •੍ޚߏจ •ؔ
+ ݴޠಛ༗ͷػೳ
•ϙΠϯλ •ߏମ
ͦͦͳΜͰ CΛษڧ͢Δͷʁ
Rubyͱ͔Pythonͱ͔ φ͍ݴޠΓ͍ͨ
౦େͩͬͯΞϧΰͰ RubyͬͯΔ͡ΌΜ
•×ίϯϐϡʔλΛಈ͔͢ •◦ίϯϐϡʔλΛཧղ͢Δ
None
ܭࢉػͷΈΛ ཧղ͢Δ
ਖ਼ͦ͜·Ͱ ਂ͘Βͳͯ͘Α͍
• ϓϩάϥϛϯάݴޠҰൠͷߟ͑ํ • Cݴޠಛ༗ͷॻ͖ํ • ͱ͔Λ͞ΒͬͱΓ·͢
Cݴޠͷجૅ
•ίʔυΛॻ͘ •ίϯύΠϧ͢Δ •࣮ߦ͢Δ Cݴޠͷجૅ
$ emacs hello.c --- #include <stdio.h> int main() { printf(“Hello,
world!\n”); return 0; }
$ gcc hello.c -o hello $ ./hello Hello, world!
#include <stdio.h> int main() { printf(“Hello, world!\n”); return 0; }
࣮ͳͯ͘ྑ͍
stdio.h = st(andar)d I(n/)O(ut).h(eader)
ඪ४ೖग़ྗ
•printf •scanf
#include <stdio.h> int main() { printf(“Hello, world!\n”); return 0; }
#include <stdio.h> int main() { printf(“Hello, world!\n”); return 0; }
#include <stdio.h> int main() { printf(“Hello, world!\n”); return 0; }
$ gcc hello.c -o hello ɹ
$ [gcc] hello.c -o hello ίϯύΠϧ༻ίϚϯυ
$ gcc [hello.c] -o hello ίϯύΠϧ͢Διʔείʔυ
$ gcc hello.c [-o] hello outfile Φϓγϣϯ
$ gcc hello.c -o [hello] ϑΝΠϧ໊
$ ./hello Hello, World
Ҏ্ɺCͷجૅ
มͷ
ͻͱͱ͓Γͷཧղ
•ม/ྻ •੍ޚߏจ •ؔ
+ ݴޠಛ༗ͷػೳ
•ϙΠϯλ •ߏମ
• ใͷอଘํ๏(σʔλߏ) • ੍ޚ/ؔ
• ใͷอଘ(σʔλߏ) • มɺྻɺ(ϙΠϯλ)ɺߏମ • ੍ޚ/ؔ • ੍ޚߏจɺؔ
ม
x = 10 y = 20
int x = 10; int y = 20;
ܭࢉػ
ON 1 OFF 0
0100101001010100...
None
•int •float, double ුಈখ(খ) •char จࣈ
• ม: 1ͭͷσʔλΛอଘ͢Δͷ • ≒σʔλʹ໊લΛ͚͓ͯ࣋ͬͯ͘ • ܕσʔλͷछྨΛද͢ ·ͱΊ
੍ޚߏจͷ
ϓϩάϥϜ্͔Β ॱ൪ʹॲཧ
ॱ൪Λม͍͑ͨʂ
ൺֱԋࢉࢠ
<ͱ͔>ͱ͔==ͱ͔
ࢄֶ
a b a < b 0 0 0 0 1
1 1 0 0 1 1 0
0ͳΒِ 0Ҏ֎ͳΒਅ
੍ޚߏจ
•if - else - ݅Ͱذ •while - ಉ͡ॲཧΛ·ͱΊΔ •for -
whileͷ্Ґ൛
if - else
͠ʙͳΒ Ͱͳ͚Ε
aͱbͰେ͖͍ํΛ ग़ྗ͍ͨ͠
int a = 10; int b = 20; if (
a < b ) { printf(“%d\n”, b); } else { printf(“%d\n”, a); }
int a = 10; int b = 20; if (
a > b ) { printf(“%d\n”, b); } else { printf(“%d\n”, a); }
while
ʙͷؒ
10͔Β1·Ͱ Χϯτμϯ͍ͨ͠
int i = 10; printf(“%d\n”, i); i = i -
1; printf(“%d\n”, i); i = i - 1; ...
10 9 8 7 6 5 4 3 2 1
i = i - 1;
int i = 10; // i: 10 int tmp =
i - 1; // i: 10 i = tmp; // i: 9
int i = 10; printf(“%d\n”, i); i = i -
1; printf(“%d\n”, i); i = i - 1; ...
int i = 10; while ( 0 < i )
{ printf(“%d\n”, i); i = i - 1; }
for
whileͷ্Ґ൛
int i = 10; while ( 0 < i )
{ printf(“%d\n”, i); i = i - 1; }
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); }
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); }
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); }
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3 2
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3 2
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3 2
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3 2 1
int i; for (i = 10; 0 < i; i
= i - 1) { printf(“%d\n”, i); } 10 9 8 7 6 5 4 3 2 1
·ͱΊ • ॲཧͷॱ൪Λม͑Δͷʹ੍ޚจΛ͏ • ݅Ͱذ͢Δ • ifͱ͔whileͱ͔͍Ζ͍Ζ͋Δ • forwhileͷ্Ґ൛Έ͍ͨͳײ͡
·ͱΊ • ଞʹdo-whileͱ͔switchͱ͔͋Δ • άάͬͯ(͋Μ·ΓΘͳ͍ؾ͕͢Δ)
None
ྻͷ
ม·ͱΊͨͭ
ม·ͱΊͯ ࣈॱʹͳΒͨͭ
a͞ΜͷମॏΛ ྸॱʹه͍ͨ͠
int a0 = 3; ... int a6 = 22; int
a7 = 24; int a8 = 27;
໊લ͚Δͷ͕ ͱͯΊΜͲ͍͘͞
int a[100]; a[0] = 3; ... a[6] = 22; a[7]
= 24; a[8] = 27;
ศརʂʂʂ
int a[100]; ܕ ྻ໊[ ֬อ͢Δ ]; a[0] = 3; ྻ໊[
ఴࣈ ] = ;
จࣈ char
จࣈྻ char[]
char name[8] = “haru067”;
ཉ͍͠จࣈ+1 Ͱ֬อ
char name[8] = “haru067”;
char name[8] = “haru067\0”;
• ྻΛ͏ͱมΛ·ͱΊΒΕΔ • จࣈྻจࣈܕ(char)ͷྻ ·ͱΊ
ߏମͷ
ߏମ දͷΑ͏ͳͷ
ͪΐͬͱ͚ͩ ྻʹࣅͯΔ
໊લ ྸ ମॏ Ұ 19 165 59 ೋ 20
172 64 ࡾ 21 183 72 ࢛ 16 159 53
struct brother { int age; double height; double weight; };
// ηϛίϩϯΘ͢Εͣʹ
struct brother ichiro; ichiro.age = 19; ichiro.height = 165; ichiro.weight
= 59; printf(“%d\n”, ichiro.age); // 19
struct brother ichiro; ichiro.age = 19; ichiro.height = 165; ichiro.weight
= 59; printf(“%d\n”, ichiro.age); // 19
brother ichiro; ichiro.age = 19; ichiro.height = 165; ichiro.weight =
59; printf(“%d\n”, ichiro.age); // 19
͍͍ͪͪstructॻ͘ͷ ΊΜͲ͏
ܕͷΑ͏ʹѻ͍͍ͨ
struct brother { char name[20]; int age; double height; double
weight; };
typedef struct { char name[20]; int age; double height; double
weight; } brother;
·ͱΊ • ߏମؔ࿈͢ΔσʔλΛ·ͱΊΔ • දΈ͍ͨͳײ͡ • ޙظͷߨٛͰׂͱॏཁͬΆ͍
ؔͷ
None
ؔ
f(x) = x * x
͍͍ͩͨ͋ͬͯΔ
int sq (int num) { return num * num; }
int main(){ int a = 3; printf(“%d\n”, sq(a)); return 0; }
Math: f(x) = x * x C: int sq (int
num) { return num * num; }
Math: f(x) = x * x C: int sq (int
num) { return num * num; }
Math: f(x) = x * x C: int sq (int
num) { return num * num; }
Math: f(x) = x * x C: int sq (int
num) { return num * num; }
Math: f(x) = x * x C: int sq (int
num) { return num * num; }
int sq (int num) { return num * num; }
ܕ ໊ؔ ( ܕ Ҿ ) { ॲཧ ؔͷܕʹ߹ͬͨฦΓ }
int sq (int num) { return num * num; }
ܕ ໊ؔ ( ܕ Ҿ, ܕ Ҿ ) { ॲཧ ؔͷܕʹ߹ͬͨฦΓ }
int sq (int num) { return num * num; }
int main(){ int a = 3; printf(“%d\n”, sq(a)); return 0; }
f(x) = x * x b = 3 f(b) =
9
ҾपΓͰ Ή͜ͱͳ͍
ฦΓ
ϙΠϯλ
None
ϙΠϯλ”ࢀর”
• มͷ”ॴ(ΞυϨε)”ΛೖΕΔม • ม: ࣗൢػͷ্ͷϘλϯ • ϙΠϯλม: ࣗൢػͷԼͷϘλϯ ্ͷϘλϯͷ”ॴ”Λ֮͑Δ ͭ·Γɺ”த”Λ֮͑ΔͷͰͳ͍
ϙΠϯλ
// ϙΠϯλͷએݴ // “ॴ”ΛೖΕΔม int *b_button;
// ϙΠϯλͷએݴ // “ॴ”ΛೖΕΔม int *b_button; b_button = &button; //
&มͷ”ॴ”Λࣔ͢
// ϙΠϯλͷએݴ // “ॴ”ΛೖΕΔม int *b_button; b_button = &button; button
= 1;
// ϙΠϯλͷએݴ // “ॴ”ΛೖΕΔม int *b_button; b_button = &button; button
= 1; printf(“%d\n”, *b_button); // 1
ϙΠϯλ”ࢀর”
ϙΠϯλࢦఆ͞Εͨ ॴͷมͷΛݟʹߦ͘
void sq (int *num1, int *num2) { num1 = &a;
num2 = &b; *num1 = *num1 * *num1; *num2 = *num2 * *num2; } int main(){ int a = 3, b = 6; sq(&a, &b); printf(“%d, %d\”, a, b);
·ͱΊ • ಉ͡ॲཧΛผͷॴͰߦ͍ͬͯΔͱ͖ ؔʹ·ͱΊΔͱݟ௨͕͠Α͘ͳΔ • ฦΓ͕ෳͩͬͨΓɺྻͷ߹ ϙΠϯλΛ͏
·ͱΊ • ϙΠϯλࢀর