I hope my formatting etc. is ok as this is the first time I post a question. Anyways, I'm searching and couldn't find an explanation why the two different function definitions/declarations are equivalent to each other:
#include <iostream>
using namespace std;
int quadrat( int x )
{
return x*x;
}
void printTable_1( int start, int end, int step, int (*func)( int x ) )
{
for ( int i = start; i <= end; i+=step )
{
cout << i << "\t" << func(i) << '\n';
}
}
void printTable_2( int start, int end, int step, int func( int x ) )
{
for ( int i = start; i <= end; i+=step )
{
cout << i << "\t" << func(i) << '\n';
}
}
int main()
{
printTable_1(1,10,1,quadrat);
printTable_2(1,10,1,quadrat);
return 0;
}
What I don't understand is that I didn't explicitely defined in the function "printTable_2" a function pointer like in the function "printTable_1" and it still expects one. Thanks in advance for the answers!