Hi I'm new to c++ and I would like to know why the following code is not working as expected:
#include <iostream>
using namespace std;
class Person
{
public:
int age;
Person(){
int age = 20;
}
};
int main()
{
Person p;
cout << p.age << endl;
}
I'm expecting to cout 20, but the program returns 0. I thought that the constructor would change age to 20 after the object is created. I tried searching for answers but the search results don't seem to answer my question.