C++ OOP Quiz - Question 9

Last Updated :
Discuss
Comments

What will be the output of the below code?

C++
#include<iostream.h>
class Point {
   int x, y;
public:
   Point(int i = 0, int j = 0) { x = i; y = j; }
   int getX() { return x; }
   int getY() { return y; }
};
int main() {
   Point p1;
   Point p2 = p1;
   cout << "x = " << p2.getX() << " y = " << p2.getY();
   return 0;
}

x = garbage value; y = garbage value

x = 0; y = 0

Compiler Error

Runtime Error

Share your thoughts in the comments
Article Tags :