



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 programming, how they are used to call a function in a program without knowing which function the user wants to call until run-time, and how they can be passed to functions, returned from functions, stored in arrays, and assigned to other function pointers. It also covers arrays of pointers to functions and their use in menu-driven systems.
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!
Problem : Suppose I want to call a function in my program, but I won't know which function the user wants to call until run‐time. Solution : Store the name of the function in a variable and use the variable (Function names are actually pointers!!) int (funcPtr) (int i); // funcPtr will hold the name // of a function that has a // prototype like // int func(int i) … funcPtr = doIt; // doIt is an actual function answer = funcPtr(num); // really a call to doIt // could also be written: answer = (funcPtr)(num);
new_node->value = new_value; new_node->next = NULL; // head should not be null, but in case it is .... if (head == NULL) { head = list_create(); } // we never insert before the dummy header, so only the // 'insert middle and end' cases are needed! for(tmp = head; tmp->next != NULL; tmp = tmp->next) { if (new_value < tmp->next->value) { new_node->next = tmp->next; tmp->next = new_node; return head; } } tmp->next = new_node; return head; } // a cheese-y test driver ... what cases are tested? which // are missed (for new version of list) int main() { List *l = list_create(); list_print("empty list ", l); int a[] = {5, 9, 7}; l = list_insert(l, a, compare); list_print("[5] ", l, output); l = list_insert(l, a+1, compare); list_print("[5 9] ", l, output); l = list_insert(l, a+2, compare); list_print("[5 7 9] ", l, output); l = list_delete(l, a+2, compare); list_print("[5 7 ] ", l, output); }