Yes, we can define function within function.
But the scope of inner function will be limited.
We can not call the inner function directly. We need to call the outer function,
this outer function will return the address of the inner function and
we can use this address to call inner function but the stack of outer function will be finished
after returning the address of inner function. So address of inner function will be garbage address.
You can do One thing :
1) Written a outer_functtion with return type is void pointer;
2) declare a inner in this outer function;
Now see the code below
#include <stdio.h>
#include <pthread.h>
void (*ptr_fun) (void);
void *f2()
{
while(1)
{
sleep(1);
ptr_fun();
}
pthread_exit(0);
}
void *outer_fun()
{
printf("\n outer function is called \n");
void inner_fun()
{
printf("\n inner function is called \n");
}
ptr_fun = inner_fun;
while(1){}
pthread_exit(0);
}
int main()
{
pthread_t f2_thread, f1_thread;
pthread_create(&f1_thread, NULL, outer_fun, NULL);
pthread_create(&f2_thread, NULL, f2, NULL);
pthread_join(f1_thread,NULL);
pthread_join(f2_thread,NULL);
return ;
}