I'm studying for an exam, and I had some quick questions. What does this code output?
I'm really tempted to say ExampleClass 3, but the way the professor asked makes it seem like a trick question.Code:
class ExampleClass {
private: int i;
public:
ExampleClass(int j) { i=j; }
int get_i() { return i; }
};
int main() {
ExampleClass objects[4] = {1,2,3,4};
ExampleClass *p;
p = &objects; // get address of objects
cout << p->get_i() << endl; // use -> to call get_i()
p = p +2;
cout << p->get_i() << endl; // which object is output?
return 0;
}