Passing pointers to functions in C
C programming language allows you to pass a pointer to a function. To do so, simply declare the function parameter as a pointer type.Following a simple example where we pass an unsigned long pointer to a function and change the value inside the function which reflects back in the calling function:
#include <stdio.h>
#include <time.h>
void getSeconds(unsigned long *par);
int main ()
{
unsigned long sec;
getSeconds( &sec );
/* print the actual value */
printf("Number of seconds: %ld\n", sec );
return 0;
}
void getSeconds(unsigned long *par)
{
/* get the current number of seconds */
*par = time( NULL );
return;
}
When the above code is compiled and executed, it produces following result:
Number of seconds :1294450468






0 comments:
Post a Comment
Dont Forget for Commets