C Programming Reference >> C Programming Reference Question Bank >>
19/07/07 - Views - Ratings :   3 of 5 / 9 Votes
Level - Advance
Question -
What is the type of temp below?
typedef int (*test) ( float * , float*)
test tmp; |
Answer -
tmp will be an int.
Explanation -
Typedef keyword in c is used to make alias name for data types. General form of usage of typedef keyword of C is shown below -
typdef oldname newname.
So according to above typedef syntax all we did was that we made a new name data type test which was same as basic int data type even after that complicated looking statement. So finally tmp end as integer variable.
Reader Comments -
| frederic
|
dont't think so.... tmp will return int but can't say type of temp is int at least ,you can't do "int j =0; tmp = j;"
|
| observer
|
This is not true. typedef int (*fncPtr)(float*, float*) is a function pointer, and hence will take only address of a function with 2 floating pointers as parameters. Therefore, typedef int (*test)(float*, float*);
int addition( float *a, float* b);
test = &addition; and call it by (*test)(1.2, 3.4);
I tested your code on a gcc compiler and it gave me compiler errors when i tried tmp =6
|
|