Function pointer in c - a simple code using struct. The same concept I saw in device driver development. So to get a clear concept I did this code.
Read this post to know how to add source code snippet to blogger.
#include <stdio.h>
struct file_ops {
int number;
int ( *open ) ( int );
};
int function_open ( int );
struct file_ops
fops = {
open: function_open,
},
gops = {
open:function_open,
};
int main ( void )
{
fops.number = 10;
fops.open ( fops.number );
gops.number = 20;
gops.open ( gops.number );
return 0;
}
int function_open ( int a ) {
static int j = 0;
printf ( "The number is : %d\n", a );
j++;
printf ( "The count is : %d\n", j );
return a;
}
Read this post to know how to add source code snippet to blogger.