I'm examining the following code in C++:
#include <iostream>
using namespace std;
class Person{
public:
int age;
Person(int age){
this->age = age;
}
};
int main()
{
Person a = Person(2);
Person temp[] = {a};
temp[0].age = 5;
cout << temp[0].age;
return 0;
}
So my guess is that when one assigns an object to a slot of an array in C++, that is equivalent to copying that object into the array.
Thus when we change that element in the array, it won't affect the original object. Is that correct?