devxlogo

Calling a Function Through a Pointer

Calling a Function Through a Pointer

The common way of calling a function through a pointer is using the pointer as if it were a function. In other words, if p is a pointer to a function called f:

 int f(int n){ return n;}int (*p)(int)=f; 


Then there’s no syntactic difference between calling f() directly, e.g.,

 int m=f(n);


and calling f() through the pointer p:

 int m=p(n);


However, it is allowed to use the (*p)(n) to call a function through a pointer:

 int m=(*p)(n);


This form was prevalent in pre-standard C and is still permitted today. You shouldn’t use it new code. However, it’s very common in legacy code so you should be familiar with it.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist