Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7916187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:42:53+00:00 2026-06-03T14:42:53+00:00

I know function call back is embedding another function pointer in the call of

  • 0

I know function call back is embedding another function pointer in the call of another function like this:

Function Declaration:

function_call_back(int x, int y, void (*functonPtr)(int x, char y , struct newStruct* sptr))


void func(int x , char y , struct newStruct* sptr1)
{
    //perform Algorithm 1 on x,y ,sptr1
}

void func2(int x , char y , struct newStruct* sptr2)
{
    //perform Algorithm 1 on x,y ,sptr2
}


void func3(int x , char y , struct newStruct* sptr3)
{
    //perform Algorithm 1 on x,y ,sptr3
}

void func4(int x , char y , struct newStruct* sptr4)
{
    //perform Algorithm 1 on x,y ,sptr4
}

main()
{
    // function calling 
    function_call_back(23, 2256, func1);
}

Here the third argument is func, as function name is equivalent to function pointer

I agree that the func here can be altered with different variation of similar function signature by adding this line in main above before call to function_call_back:

 typedef void (*fptr)(int int x , char y , struct newStruct* ptr);

  fptr f1 = func2; // or func3, or func4

  function_call_back(23, 2256, f1);

The third argument is func, as function name is but I was wondering this can be achieved in the below way also, by simply adding the function-calling code in the call to function_call_back:

function_call_back(23, 2256, functionCallingcode); //third argument is func 

The new declaration of function_call_back is:

function_call_back(int x, int y, int functionCallingCode)

And its new definition is:

void function_call_back(int x, int y, int functionCallingCode)
{
switch(functionCallingCode)
case 1:
func1(1,"g",sptr1);
break;

case 2:
func2(1,"c",sptr2);

break

case 3:
func3(1,"d",sptr3);
break;

case 4 : 
func4(1,"s",sptr4);
break ;

default : 
 printf("Wrong Function calling code");

}
}

Then why to use function pointer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:42:56+00:00Added an answer on June 3, 2026 at 2:42 pm

    With the switch statement, you can call every function that you choose to code into your callback function. You are guaranteed that only one of your known collection of functions can be called.

    With the function pointer, you can call any function that you may define at a later and completely unrelated point in your development. You’re free to define and use any callback function with a matching signature.

    In other words, the switch allows you to branch among a bounded set of choices, while the function pointer gives you unbounded flexibility. Usually there’s little reason to prefer anything else over the function pointer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can do this to inject CSS like this: $(document).ready(function() {
I know you can pass arguments through the RunWorkerAsync function call when you first
I want to know how to call Ajax function Recursively. My ajax code is
Is there a function I can call to know if a certain element is
Does anybody know how to debug call to undefined function init_set , when trying
I know about the basic concept of virtual function and run-time call. But i
I know there are at least three popular methods to call the same function
I'm working on creating a call back function for an ASP.NET cache item removal
i wanted to know how can we implement call back mechanism in .net, since
I'm doing something like this: @protocol CallbackDelegate -(void) performCallback; @end @interface MyObject : NSObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.