Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of Function in C or C++

I have a simple question:

What is the type of function in C or C++

As we can have pointers to function in C or C++, that means functions should have a specific type otherwise type checking during pointers to function creation have no meaning.

Can someone explain me, I am on the correct path or not?

If I am on the right path, How can I find the type of function?

like image 722
neel Avatar asked Oct 27 '25 18:10

neel


1 Answers

Syntax for function pointers

The type of a function in C/C++ includes both the return type and the types of input parameters .

Consider the following function declaration:

int function(char, float);

A pointer to that function has the following type:

int (*funptr)(char, float); 

Similarly in general :

returntype function (argtype1, argtype2, argtype3)

A corresponding pointer to such a function is

returntype (*ptr) (atgtype1, atgtype2, atgtype3);  

There are be many different types of functions. Find a useful reference on function pointers here.

Also, this classification is based on the return type and argument types. Functions can also be classified on the basis of scope of their accessibility. like global functions, static functions etc. See here for a short introduction.

like image 185
Grijesh Chauhan Avatar answered Oct 30 '25 07:10

Grijesh Chauhan