Pointer to a function in C.

 

01  #include<stdio.h>
02
03 int add(int,int); // fun_prototype
04
05 int main()
06 {
07 int ans;
08
09 int (*p)(int,int);
10
11 /*
12 p is a pointer to a function,
13 which take 2 integers arguments
14 and return an integer.
15 */
16
17 p=add; // p now points to add function
18
19
20 ans=(*p)(10,20); // calling of add() funtion using function pointer
21
22
23 printf("answer is %d",ans);
24
25 return 0;
26 }
27
28 int add(int a,int b)
29 {
30 return (a+b);
31 }
 
 OUTPUT :

answer is 30

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.