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;
}
        #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: Option C
Related Questions on Object Oriented Programming in C plus plus
What is the process of creating an instance of a class called in C++?
A. Encapsulation
B. Polymorphism
C. Inheritance
D. Instantiation
A. The process of creating multiple instances of a class
B. The process of hiding the implementation details of a class
C. The process of deriving a new class from an existing class
D. The process of defining functions within a class
What is the access specifier that allows members to be accessed from outside the class in C++?
A. protected
B. public
C. friend
D. None of the above

Join The Discussion