SlideShare a Scribd company logo
1 of 9
Abu Bakr Mohamed Ramadan
eng.abubakr@gmail.com
Content:
 Using an array of pointers to functions,
 Example on array of pointers to functions,
 Using typedef with the function pointer,
 Declaring function pointers in structure,
 Example on using function pointers in structure,
Using an array of pointers to functions,
 //Declaration of array of function pointer
int (*apfArithmatics [3])(int,int)
 //Initialization of array of function pointer
int (*apfArithmatics [3])(int,int) =
{AddTwoNumber,SubTwoNumber,MulTwoNumber};
 //Calling the Add function using index of array
iRetValue = (*apfArithmatics [0])(20,10);
 The array of function pointers offers the facility to access the function using the
index of the array.
Using an array of pointers to functions,
 Example on array of pointers to functions,
Using typedef with the function pointer
 It is convenient to declare a type definition for function pointers like:
 /* function pointer */
typedef int (*pfunctPtr)(int, int);
 Before:
 int (*pfunctPtr)(int, int) = AddTwoNumbers;
 iRetValue = (*pfunctPtr)(a, b);
 After:
 pfunctPtr Calculation = AddTwoNumbers;
 iRetValue = Calculation(a,b);
Using typedef with the function pointer
 // typedef of array of function pointers
typedef int (*apfArithmatics[3])(int,int);
{{
 Before:
 int (*apfArithmatics [3])(int,int) = {AddTwoNumber,SubTwoNumber,MulTwoNumber};
 After:
 apfArithmatics aArithmaticOperation = {AddTwoNumber,SubTwoNumber,MulTwoNumber};
Declare function pointers in structure
 A structure is a collection of variables under a single name. These variables
can be of different types,
 A structure is a convenient way of grouping several pieces of related
information together.
 In C language we cannot create a member function in the structure but with the
help of pointer to function, we can provide the facility to user to store the
address of the function.
Declare function pointers in structure
 First define a function pointer for example:
 typedef int (*pfoperation)(int a , int b );
 Then define the struct,
 typedef struct S_sMath
{
int result ; // to store the resut
pfoperation operation; // funtion pointer
} sMath;
 Then Declare the struct
 sMath smath_operation;
 OR
 sMath * psSmath_operation = NULL;
 Initialize the function pointer:
 Smath_operation.Operation = add;
 OR
 psSmath_operation->Operation = add;
 Calling function using pointer to function declared in a
struct
 Smath_operation.result =
Smath_operation.Operation(5,3);
 OR
 psSmath_operation->result =
psSmath_operation->Operation(5,3);
Declare function pointers in structure
 Example on using function pointers in structure,

More Related Content

What's hot (20)

Pointers in C
Pointers in CPointers in C
Pointers in C
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Pointers
PointersPointers
Pointers
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Function in c
Function in cFunction in c
Function in c
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
POINTERS IN C
POINTERS IN CPOINTERS IN C
POINTERS IN C
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Function in c
Function in cFunction in c
Function in c
 
Tail recursion
Tail recursionTail recursion
Tail recursion
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
This pointer
This pointerThis pointer
This pointer
 
C string
C stringC string
C string
 
pointers
pointerspointers
pointers
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 

Similar to Pointer to function 2

pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphismramya marichamy
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptgeorgejustymirobi1
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxvekariyakashyap
 
Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphismSangeethaSasi1
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 
C-Programming Function pointers.pptx
C-Programming  Function pointers.pptxC-Programming  Function pointers.pptx
C-Programming Function pointers.pptxLECO9
 
C-Programming Function pointers.pptx
C-Programming  Function pointers.pptxC-Programming  Function pointers.pptx
C-Programming Function pointers.pptxSKUP1
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersANUSUYA S
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
C++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageC++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageHariTharshiniBscIT1
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Meghaj Mallick
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdfNehaSpillai1
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyworldchannel
 

Similar to Pointer to function 2 (20)

pointer, virtual function and polymorphism
pointer, virtual function and polymorphismpointer, virtual function and polymorphism
pointer, virtual function and polymorphism
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).ppt
 
c program.ppt
c program.pptc program.ppt
c program.ppt
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
Pointer and polymorphism
Pointer and polymorphismPointer and polymorphism
Pointer and polymorphism
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
C-Programming Function pointers.pptx
C-Programming  Function pointers.pptxC-Programming  Function pointers.pptx
C-Programming Function pointers.pptx
 
C-Programming Function pointers.pptx
C-Programming  Function pointers.pptxC-Programming  Function pointers.pptx
C-Programming Function pointers.pptx
 
C1320prespost
C1320prespostC1320prespost
C1320prespost
 
C++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about PointersC++ - UNIT_-_IV.pptx which contains details about Pointers
C++ - UNIT_-_IV.pptx which contains details about Pointers
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
C++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming languageC++ Class & object pointer in c++ programming language
C++ Class & object pointer in c++ programming language
 
08 -functions
08  -functions08  -functions
08 -functions
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdf
 
U3.pptx
U3.pptxU3.pptx
U3.pptx
 
unit 3 ppt.pptx
unit 3 ppt.pptxunit 3 ppt.pptx
unit 3 ppt.pptx
 
Unit 8
Unit 8Unit 8
Unit 8
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 

More from Abu Bakr Ramadan

Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4Abu Bakr Ramadan
 
Real time operating systems (rtos) concepts 3
Real time operating systems (rtos) concepts 3Real time operating systems (rtos) concepts 3
Real time operating systems (rtos) concepts 3Abu Bakr Ramadan
 
Real time operating systems (rtos) concepts 9
Real time operating systems (rtos) concepts 9Real time operating systems (rtos) concepts 9
Real time operating systems (rtos) concepts 9Abu Bakr Ramadan
 
Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8Abu Bakr Ramadan
 
Real time operating systems (rtos) concepts 7
Real time operating systems (rtos) concepts 7Real time operating systems (rtos) concepts 7
Real time operating systems (rtos) concepts 7Abu Bakr Ramadan
 
Real time operating systems (rtos) concepts 5
Real time operating systems (rtos) concepts 5Real time operating systems (rtos) concepts 5
Real time operating systems (rtos) concepts 5Abu Bakr Ramadan
 
Real time operating systems (rtos) concepts 1
Real time operating systems (rtos) concepts 1Real time operating systems (rtos) concepts 1
Real time operating systems (rtos) concepts 1Abu Bakr Ramadan
 

More from Abu Bakr Ramadan (7)

Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4Real time operating systems (rtos) concepts 4
Real time operating systems (rtos) concepts 4
 
Real time operating systems (rtos) concepts 3
Real time operating systems (rtos) concepts 3Real time operating systems (rtos) concepts 3
Real time operating systems (rtos) concepts 3
 
Real time operating systems (rtos) concepts 9
Real time operating systems (rtos) concepts 9Real time operating systems (rtos) concepts 9
Real time operating systems (rtos) concepts 9
 
Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8Real time operating systems (rtos) concepts 8
Real time operating systems (rtos) concepts 8
 
Real time operating systems (rtos) concepts 7
Real time operating systems (rtos) concepts 7Real time operating systems (rtos) concepts 7
Real time operating systems (rtos) concepts 7
 
Real time operating systems (rtos) concepts 5
Real time operating systems (rtos) concepts 5Real time operating systems (rtos) concepts 5
Real time operating systems (rtos) concepts 5
 
Real time operating systems (rtos) concepts 1
Real time operating systems (rtos) concepts 1Real time operating systems (rtos) concepts 1
Real time operating systems (rtos) concepts 1
 

Recently uploaded

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 

Recently uploaded (20)

Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 

Pointer to function 2

  • 1. Abu Bakr Mohamed Ramadan eng.abubakr@gmail.com
  • 2. Content:  Using an array of pointers to functions,  Example on array of pointers to functions,  Using typedef with the function pointer,  Declaring function pointers in structure,  Example on using function pointers in structure,
  • 3. Using an array of pointers to functions,  //Declaration of array of function pointer int (*apfArithmatics [3])(int,int)  //Initialization of array of function pointer int (*apfArithmatics [3])(int,int) = {AddTwoNumber,SubTwoNumber,MulTwoNumber};  //Calling the Add function using index of array iRetValue = (*apfArithmatics [0])(20,10);  The array of function pointers offers the facility to access the function using the index of the array.
  • 4. Using an array of pointers to functions,  Example on array of pointers to functions,
  • 5. Using typedef with the function pointer  It is convenient to declare a type definition for function pointers like:  /* function pointer */ typedef int (*pfunctPtr)(int, int);  Before:  int (*pfunctPtr)(int, int) = AddTwoNumbers;  iRetValue = (*pfunctPtr)(a, b);  After:  pfunctPtr Calculation = AddTwoNumbers;  iRetValue = Calculation(a,b);
  • 6. Using typedef with the function pointer  // typedef of array of function pointers typedef int (*apfArithmatics[3])(int,int); {{  Before:  int (*apfArithmatics [3])(int,int) = {AddTwoNumber,SubTwoNumber,MulTwoNumber};  After:  apfArithmatics aArithmaticOperation = {AddTwoNumber,SubTwoNumber,MulTwoNumber};
  • 7. Declare function pointers in structure  A structure is a collection of variables under a single name. These variables can be of different types,  A structure is a convenient way of grouping several pieces of related information together.  In C language we cannot create a member function in the structure but with the help of pointer to function, we can provide the facility to user to store the address of the function.
  • 8. Declare function pointers in structure  First define a function pointer for example:  typedef int (*pfoperation)(int a , int b );  Then define the struct,  typedef struct S_sMath { int result ; // to store the resut pfoperation operation; // funtion pointer } sMath;  Then Declare the struct  sMath smath_operation;  OR  sMath * psSmath_operation = NULL;  Initialize the function pointer:  Smath_operation.Operation = add;  OR  psSmath_operation->Operation = add;  Calling function using pointer to function declared in a struct  Smath_operation.result = Smath_operation.Operation(5,3);  OR  psSmath_operation->result = psSmath_operation->Operation(5,3);
  • 9. Declare function pointers in structure  Example on using function pointers in structure,