How can we call function using pointer ?

I want to place function call using pointer how can i do it? it is quite difficult i am facing problem in my program.


2 Answers
1-2 of  2
2 Answers
  • defining a function pointer: 
    <return type> (*name)(<argument list>); 
    example,
    int (*strcmp_p)(const char *, const char*); 
    Typedefs vastly simplifies things:
    typedef void (*func_p)(int, char *, ...); 
    func_p ptr_to_func, *ptr_to_ptr_to_func, arr_of_func_ptrs[10];

    Assigning, from previous examples:
    strcmp_p = strcmp; 
    or, using old-style syntax:
    strcmp_p = &strcmp;

    calling through pointer:
    int result = strcmp_p("foo", "bar");
    or old-style syntax:
    int result = (*strcmp_p)("foo", "bar");

C Language

Didn't get the answer.
Contact people of Talent-C Language directly by clicking here