









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The concept of function pointers in C and Unix systems. Function pointers allow for efficient and elegant function calls, runtime binding, and the ability to pass and return functions as arguments. why function pointers are used, how to define and use them, and provides examples using the qsort and bubblesort functions.
Typology: Exercises
1 / 16
This page cannot be seen from the preview
Don't miss anything!
int foo( ){
} int main (int argc, char* argv[]) {
foo() ; ……
main
foo
main:.LFB6:
pushq
%rbp
.LCFI2:
movq
%rsp, %rbp
.LCFI3:
subq
$32, %rsp
.LCFI4:
movl
%edi, -20(%rbp)
movq
%rsi, -32(%rbp)
movl
$10, -4(%rbp)
movl
-4(%rbp), %edi
call
foo
leaveret
Assembly code
Functions that return function pointers
typedef int (*Ptr)(int,int);
An array of char *’s
guna
andy
me
Write the compare function to sort by alpha orderInt (*strcomp)(const void * a, const void * b))
Guna
Andy
Me
Write the compare function to sort by name:int (*nodecomp)(const void * a, const void * b))
Generic Bubble sort with
function pointers
typedef int (cmp)(const void, int , int);typedef int (swap)(void, int, int); int bubblesort(void* A, int n, cmp cfn, swap sfn){