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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 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 26 views
1 answer 29 views
1 answer 77 views
1 answer 41 views
...