My professor showed us this code:
timerX(int x){
int times(int y){
return x * y;
}
return times;
}
How does this work in C(using GCC compiler)? He said that as soon as the function disappears the inside function disappears? I appreciate any tips or advice.
It’s called a nested function, a GNU extension. Basically
the inner function can acess the local variables of the outer function (the ones declared prior to its apparition)
the inner function can only be called from outside via function poinyers but not after the containing function has terminated if the inner function accesses objects from its parent
In your example, calling that function pointer from outside will probably be illegal.