whats wrong with the following 2 programs? is it stricly a memory management problem which depends where u compile it?
#include <iostream.h>
#include <string.h>
char *foo1()
{
char b[10];
strcpy(b, "hello");
char *str = b;
return str;
}
char *foo2()
{
char b[10];
strcpy(b, "goodbye");
char *str = b;
return str;
}
main()
{
char *a;
char *b;
a = foo1();
cout << a << endl;
b = foo2();
cout << a << " " << b << endl;
}
and this one:
#include <iostream.h>
#include <string.h>
main()
{
char *str;
*str = 'x';
cout << *str << endl;
}