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
ОПК, семинар №8
Search
Ilya
March 12, 2015
Education
0
54
ОПК, семинар №8
Указатели на функции
Ilya
March 12, 2015
Tweet
Share
More Decks by Ilya
See All by Ilya
Программирование на ЯВУ, семинар 3
ilya
0
160
Программирование на ЯВУ, семинар 2
ilya
0
72
ОПК, семинар №6
ilya
0
74
ОПК, семинар №4
ilya
0
110
ОПК, семинар №2
ilya
0
85
Other Decks in Education
See All in Education
Gaps in Therapy in IBD - IBDInnovate 2025 CCF
higgi13425
0
480
ビジネスモデル理解
takenawa
0
5k
OpenSourceSummitJapanを運営してみた話
kujiraitakahiro
0
700
2025年度春学期 統計学 第2回 統計資料の収集と読み方(講義前配付用) (2025. 4. 17)
akiraasano
PRO
0
140
新卒研修に仕掛ける 学びのサイクル / Implementing Learning Cycles in New Graduate Training
takashi_toyosaki
1
150
データ分析
takenawa
0
5k
JOAI2025講評 / joai2025-review
upura
0
160
Virtual and Augmented Reality - Lecture 8 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.7k
生成AIとの上手な付き合い方【公開版】/ How to Get Along Well with Generative AI (Public Version)
handlename
0
470
2025/06/05_読み漁り学習
nag8
0
140
SkimaTalk Introduction for Students
skimatalk
0
380
人になにかを教えるときに考えていること(2025-05版 / VRC-LT #18)
sksat
4
1k
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
700
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
What's in a price? How to price your products and services
michaelherold
246
12k
Unsuck your backbone
ammeep
671
58k
Speed Design
sergeychernyshev
32
1k
KATA
mclloyd
29
14k
Fireside Chat
paigeccino
37
3.5k
Balancing Empowerment & Direction
lara
1
370
Making Projects Easy
brettharned
116
6.3k
Transcript
Указатели на функции
#include <stdio.h> #include <stdlib.h> double long_calculation(double x, unsigned n) {
double result = 1.0; unsigned i; for(i = 0; i < n; i++) { result *= x; sleep(1); } return result; } int main() { double my_power = long_calculation(2.0, 5); printf("Result: %lf\n", my_power); return 0; }
Callbacks void printer(int i) { printf("Progress: %d%% complete\n", i); }
int main() { void (*printer_func)(int); printer_func = &printer; printer_func(20); return 0; }
double long_calculation(double x, unsigned n, void (*callback)(int)) { double result
= 1.0; unsigned i, progress; for(i = 0; i < n; i++) { result *= x; progress = (unsigned) (((double) i)/ n * 100); callback(progress); sleep(1); } return result; }
typedef void (*callback_func)(int); double long_calculation(double x, unsigned n, callback_func callback);
int main() { callback printer_func = &printer; double my_power = long_calculation(2.0, 3, printer_func); printf("Result: %lf\n", my_power); return 0; }
void bubble_sort(int *base, size_t size) { int temp; size_t i,
j; for(i = 0; i < size; i++) { for(j = i; j < size; j++) { if(base[i] > base[j]) { temp = base[i]; base[i] = base[j]; base[j] = temp; } } } } Абстракция
int main() { int array[] = {1, 9, 5, 4,
7, 2, 4, 6}; size_t length = sizeof(array)/sizeof(int); bubble_sort(array, length); size_t i; for(i = 0; i < length; i++) { printf("%d ", array[i]); } printf("\n"); return 0; }
void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *,
const void *)); int greater_than(const void* pleft, const void* pright) { int left = *(int*) pleft; int right = *(int*) pright; return left > right; } qsort(array, length, sizeof(int), greater_than);
int less_than(const void* pleft, const void* pright) { int left
= *(int*) pleft; int right = *(int*) pright; return left < right; } qsort(array, length, sizeof(int), less_than);
void (*signal(int, void(*)(int)))(int); Ужасы языка С
typedef void (*signal_handler)(int signum); void (*signal(int, void(*)(int)))(int); signal_handler signal(int signum,
signal_handler handler);