Tests

Hi c++men.

Recently bought a book and viewed some exercises from it.
The task is to find error in this code.

1
2
3
4
5
char* f(char *s)
{
char ch = 'A';
return &ch;
}


Apparently the error is not explicit, cause code compiles fine.
First I thought that return types do not match.
Would be grateful for any suggestions with explanations.
The error is simple: Never return a pointer to a local variable
Topic archived. No new replies allowed.