#include <stdio.h>
int main()
{
void foo();
printf("1 ");
foo();
}
void foo()
{
printf("2 ");
}
Output:
1 2
How declaring functions inside functions work? Does it mean that foo() function can only be called by main()?
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.
A function defined inside another function is called a nested function. Nested functions can access variables of the enclosing scope. In Python, these non-local variables are read-only by default and we must declare them explicitly as non-local (using nonlocal keyword) in order to modify them.
A function is called “nested” when it is created inside another function. It is easily possible to do this with JavaScript.
Yes, you can declare, but you cannot define. Also, you can declare function as many times you want, but define only once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With