1,389 views
0 votes
0 votes
typedef int (*test)(float*, float*);
test tmp;

 

 

 

i am unable to understand the code ,please help!

2 Answers

Best answer
5 votes
5 votes

To understand this you have to understand the typedef. Typedef is a facility provided by C language, which can be used to rename the long data type. For example. 

//Suppose you want to declare a variable "a" of type "unsigned long long int"
// then you have to write 
unsigned long long int a;
// but supposed you have to declare 100's of variable of this type at 100 different 
// location then wrting "unsigned long long int" can be tyring

// So for this purpose we use "typedef", here is an example

typedef unsigned long long int ulli;

// Now whereever i want a variavle of type "unsigned long long int", i do not have
// to write "unsigned long long int". i just have to write "ulli", and that will do our work
// for example

ulli a;

If you notice very carefully then you will understand that the last word (i.e. ulli) is the replacement of all other words (i.e. unsigned long long int)

Now concentrate in your example.


typedef int (*test)(float*, float*);

// If you carefully check the above line then you will see that "int" is the type 
// which you are replacing the word "(*test)(float*, float*)". 
// But the technical issues is that "(*test)(float*, float*)" is represented by a single name
// "test". Because "test" is the "pointer to function which accept two parameter, both 
// pointer to float". 
// So basically "test" is representing "int". so, we can use "test" to declare an integer variable

#include <stdio.h>

int main(void) {
	typedef int (*test)(float*, float*);
	test tmp;
	scanf("%d",&tmp);
	printf("%d",tmp);
}
// Run the above program to understand it. 
selected by
0 votes
0 votes

No related questions found