Below, we declare a pointer to a function that is passed void and returns void:
void (*foo)();
No. In C, an empty parameter list means nothing is specified about what is passed to the function for backwards compatibility with K&R C. To specify that the function has no parameters, you need to do:
void (*f)(void);
You should also mention that you can call a pointed to function explicitly since it occurs in a lot of code this way:
printf("%d squared is %d\n", n, (*fptr1)(n));
You should also mention that you can have a typedef of function; see here.
You should also mention that you can pass a pointer to function as a parameter without a typedef:
int compute(int (*operation)(int, int), int num1, int num2);
even though it's generally recommended that you use a typedef to make things more readable.
Your select function doesn't return anything if the argument isn't either a + or -: you should handle that case.
Software Engineer interested in Embedded Systems Design, Embedded Software, Electrical Engineering, and Electronics.
Also Interested in Automation Tools, Data Analytics, and BI Solutions.
No. In C, an empty parameter list means nothing is specified about what is passed to the function for backwards compatibility with K&R C. To specify that the function has no parameters, you need to do:
You should also mention that you can call a pointed to function explicitly since it occurs in a lot of code this way:
You should also mention that you can have a
typedef
of function; see here.You should also mention that you can pass a pointer to function as a parameter without a
typedef
:even though it's generally recommended that you use a
typedef
to make things more readable.Your select function doesn't return anything if the argument isn't either a
+
or-
: you should handle that case.Thanks very much for your comment, it is really valuable.