Trivial doubt about C function pointer

Hi,

In the below C code,

#include <stdio.h>

void print() {
    printf("Hello\n");
}

int main() {
   void (*f)() = (void (*)()) print;
   f();   
   (*f)();
}

I wonder, how the syntaxes "f()" and "(*f)()" are treated as same without any error? Is this an improvement or ANSI/ISO standard?

This is part of the C standard. Because the compiler can unambiguously determine that f in is a function pointer, it knows that "f()" can't mean anything else other than "a call to a function pointed to by f". It's a bit like being able to use p[0] whether p is an array or a pointer.

1 Like