Can we have a nested function in C? What is the use of nested functions? If they exist in C does their implementation differ from compiler to compiler?
Nested functions are not a part of ANSI C, however, they are part of Gnu C.
No, they don't exist in C.
They are used in languages like Pascal for (at least) two reasons:
No you can't have a nested function in C
. The closest you can come is to declare a function inside the definition of another function. The definition of that function has to appear outside of any other function body, though.
E.g.
void f(void)
{
// Declare a function called g
void g(void);
// Call g
g();
}
// Definition of g
void g(void)
{
}