Possible Duplicate:
Pointer to local variable
#include <iostream>
using namespace std;
char* func();
int main() {
char* str;
str = func();
cout<<str;
return 0;
}
char* func() {
char * str;
char p[] = "priyanka is a good girl";
str = p;
cout<<str<<"\n";
return str;
}
gives the output,
priyanka is a good girl
priy
I did not understand what just happened here, why an incomplete array was given as output. I am a little new with this. Please help.