If I have the following basic C++ program:
#include <iostream>
using namespace std;
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
};
void CRectangle::set_values (int a, int b) {
x = a;
y = b;
}
int main () {
CRectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area() <<endl;
cout <<&rect<<endl;
cin.get();
return 0;
}
is the last print statement printing the address of the variable rect or the address of the object? are they the same? or are they the same?
They are the same. It’s printing the address of rect which is the same as the address of the object. Rect is on the stack, and thus the entire object is as well.