First and foremost you are assigning nameValue to a variable local to the function setName, which means that the class variable name is still unitialized when you return it in getName, hence the strange output.
The char name[]; declaration is also incorrect, C++ does not allow for variable length arrays or arrays with unspecified bounds unless they are immediately initialized in which case the size will be deduced given the size of the assigned string.
On that note, warnings must have been issued by your compiler, if not, crank them up, or better yet, make it treat warnings as errors, you'll have more robust code.
For the purpose of your assignment you should just go ahead and use pointers, a small problem arises because C++ does not allow for assignment of string literals to char* variables, this is easily fixed if you use const char*, your compiler may allow the former but it is illegal as per C++ rules.
Applying the corrections above, your code should look more like this:
class human { const char* name; public: void setName(const char *nameValue); const char* getName(); }; void human::setName(const char *nameValue) { name = nameValue; } const char* human::getName(){ return name; } int main() { human myHuman; const char* name = "walter"; myHuman.setName(name); const char* result3 = myHuman.getName(); cout << "My human has a name of " << result3 << endl; return EXIT_SUCCESS; }
std::stringchar*instead ofstd::string.