I was trying to declare a function pointer that points to any function that returns the same type. I omitted the arguments types in the pointer declaration to see what error will be generated. But the program was compiled successfully and executed without any issue.
Is this a correct declaration? Shouldn't we specify the arguments types?
#include <stdio.h>
#include <stdlib.h>
void add(int a, int b)
{
printf("a + b = %d", a + b);
}
void (*pointer)() = &add;
int main()
{
add(5, 5);
return 0;
}
Output:
a + b = 10
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…