Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,700 questions

57,013 answers

573 users

How to call to a function using pointer to function in C

2 Answers

0 votes
#include <stdio.h> 

int (*functionPointer)(const char *s);

int myPuts(const char *s)
{
    puts("This string is from my function:");
    puts(s);
    
    return 1;
}

int main(int argc, char **argv)
{
    functionPointer = puts;
    functionPointer("puts function\n");

    functionPointer = myPuts;
    functionPointer("myPuts function\n");

    return 0;
}


/*
run:

puts function

This string is from my function:
myPuts function

*/


answered Apr 16, 2015 by avibootz
0 votes
#include <stdio.h>
 
int (*functionPtr)(int, int);
int sum_function(int a, int b);

int main(void)
{
    functionPtr = sum_function;
    
    int s = (*functionPtr)(7, 3);
    printf("%d", s);
    
    return 0;
}

int sum_function(int a, int b) 
{
    return a + b;
}

/*
run:
 
10

*/

 



answered Nov 25, 2015 by avibootz

Related questions

1 answer 240 views
1 answer 195 views
1 answer 187 views
1 answer 232 views
1 answer 346 views
1 answer 248 views
248 views asked Apr 5, 2024 by avibootz
1 answer 246 views
...