A friend of mine once wrote a function as follows. int * func() { int i; for (int k=0;k<200;k++) //Do something here .... return &i; } I think it is faulty . What is wrong here?
Nothing is wrong. You are wrong.
Loops are not allowed inside the function scope, Since it degrades performance
My friend tried to return a pointer to a local function variable , which is invalid once the function call compltes.
The value i is not properly initialised, SO it may contain some garbage .