0

help me to understand the copest of pointers to function with this following example . i was referring balagurusamy book of 'c' but was unable to understand this concept i also googled but didnt understood the concept


here is the code

#define PI 3.14
double y(double);
double cos(double);
double table (double(*f)(),double,double,double);
main()
{
    printf("table of y(x)=2*x*x-x+1\n\n");
    table(y,0.0,2.0,0.5);
    printf("\ntable of cos(x)\n\n");
    table(cos,0.0,PI,0.5);
}
double table(double(*f)(),double min,double max,double step)
{
    double a, value;
    for(a=min;a<=max;a+=step)
    {
        value=(*f)(a);
        printf("%5.2f  %10.4f\n",a,value);
    }
}
double y(double x)
{
    return(2*x*x-x+1);
}

if u could explain me in detail about the concept of "pointes to function" then it would be really very very helpful

sagar patel
  • 31
  • 1
  • 5

1 Answers1

0

The function is just a piece of machine code. Machine code is just bytes of data coding instructions for CPU. That is, on the lowest level, the code and the data are not fundamentally different. So the concept of pointer to code is not too different from the pointer to data.

Matt
  • 13,674
  • 1
  • 18
  • 27