Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A
{
int a;
A() { a = 5;}
};int main()
{
A *obj = new A;
cout << obj->a;
}

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A
{
int a;
A() { a = 5;}
};

int main()
{
A *obj = new A;
cout << obj->a;
}
a) 5
b) Garbage value
c) Compile-time error
d) Run-time error

Answer: c
Explanation: As Test() constructor is private member of the class therefore cannot be accessed from the outside world therefore the program gives error.

Join The Discussion