# Thread: how to pass a function as a parmeter to a function?

1. ## how to pass a function as a parmeter to a function?

OS: linux
compiler: gcc version 3.3.5 (Debian 1:3.3.5-5)
editor: vi
level: beginner

Hello,

I am working through a tutorial at: http://vergil.chemistry.gatech.edu/r...al/basic2.html, which demonstrates how to pass a function as parameter to a function.

I've tried replicating the method shown, but come up against some problems:

Code:
```#include <stdio.h>

int squared(int x){return x*x;};
int cubed(int y ){return y*y*y;};
int result(int F(int))
{

int a;
a=F(int);
return a;
};

int main()
{
int x = 1;

for (;x < 10;x++)
{
printf("squared%i\t",result(squared(x)));
printf("cubed%i\t",result(cubed(x)));
}
return 0;
}```
errors returned compiled with gcc play.c :
play.c: In function `result':
play.c:9: error: parse error before "int"
play.c: In function `main':
play.c:20: warning: passing arg 1 of `result' makes pointer from integer without a cast
play.c:21: warning: passing arg 1 of `result' makes pointer from integer without a cast

I would be grateful if someone could point me in the right direction on how to pass function(s) as parameter(s)

Thanks

Billy

Code:
```#include <stdio.h>

int squared(int x){return x*x;};
int cubed(int y ){return y*y*y;};
int result(int (*F)(int), int value)
{
int a;
a=F(value);
return a;
};

int main()
{
int x;

for (x=1;x < 10;x++)
{
printf("squared %i\t",result(squared,x) );
printf("cubed %i\n",result(cubed,x) );
}
return 0;
}```
Check out http://www.function-pointer.org/

3. ## Thanks Salem

Thanks Salem for your time and help!

Regards

Billy