I want to understand how a pointer to function works and how the functions are called in C.
In this example:
#include <stdio.h>
void invoked_function();
int main(void) {
void(*function)();
function = invoked_function;
function(); //First way to call invoked_function
(*function)(); //Second way to call invoked_function
return 0;
}
void invoked_function() {
printf("Hi, I'm the invoked function\n\n");
}
I call the function invoked_function
using function();
and (*function)();
, both work actually.
If the first one contanis the memory address of invoked_function
, and the second contains the first byte of the code of invoked_function
, why are working both?