Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Apr 30, 2001

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.
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date