Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
When foo() is being called first, compiler has to keep the every stack and finally, stack overflow.
In second case, your compiler is doing tail optimization and has freedom to drop the stack for previous recursive call. That's why it goes into a infinite loop because there is no stack overflow.
recursive loop is quite evident.. this is as per virtual call mechanism B::fun()
- anand.k.prasad February 28, 2012will get called and will kip on printing "B's f() called" till stack memory exhaust.
the Seg fault is due to stack full.