Define and initialize this data type in C programming

Can anyone tell me if this is the correct definition of this data type, and if the way I initialized is correct?

typedef int const * (* const DataOne)(const int *);

      

=> The above datatype shows a constant pointer to a function that takes a pointer to a constant int

as a parameter and returns a pointer to a constant int

.

=> initialized and declared: DataOne = &myFunction(7);

+3


source to share


1 answer


typedef int const * (* const DataOne)(const int *);

      

=> the above datatype shows a constant pointer to a function that takes a pointer to an int constant as a parameter and returns a pointer to an int constant.

Right.

=> initialized and declared: DataOne = & myFunction (7);



Wrong. A function pointer assignment cannot be performed on a function call (i.e. you cannot have actual arguments for parameters). Also, DataOne is a type, not a variable. So it should look something like this:

int const * myFunction(const int*);
DataOne myPointer = myFunction;  // &myFunction would also work

      

Declare an equivalent function pointer without a type:

int const * myFunction(const int*);
int const * (* const functionPointer)(const int *) = myFunction;

      

+8


source







All Articles