[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: typedef int (*procref)();
Kugan,
>
> typedef int (*procref)();
>
This means that procref is a new type that User has defined. This procref will hold
the pointer to a function which returns an integer and accepts void as arguments. The
Following code will make it more clear for U.
#include<stdio.h>
/*defining a new type procref */
typedef int (*procref)();
/*
* This function just returns 5.
*
*/
int Five ()
{
return 5;
}
/*
* This function just returns 6.
*
*/
int Six ()
{
return 6;
}
main()
{
/* procref is the type and func is the instance of procref. It now holds the pointer
** to the function Five
*/
procref func = Five;
/* Should print 5, the return value of Five() */
printf("\n%d", (*func)());
/* Now func points to function Six */
func = Six;
/* Should return 6, the return value of function 6 */
printf("\n%d", (*func)());
}
mallik.