0
What is the output of this program and how? please explain me if u can
class A public : int x=2; A(){x++;} ~A(){x++;} }; int main(){ A ob; cout <<ob.x; }
8 Respuestas
+ 2
~A() is called destructor. It gets called the moment your scope of your program gets over. Over here there is no effect of destructor on the output because it is displayed before the scope of program gets over.
+ 1
first, you need to put "{" after A.
output will be 3.
when you create object of class A, i.e.
A ob;
your constructor A() automatically gets invoked and increments the value of x to 3.
+ 1
final output = 3
0
what is the final output result??
0
thanks brother
0
what does that '~' indicate before A()
0
I think the program is not correct
0
@samuel If you are pointing to syntax error "{", yeah, there is that problem. But I gave the answer considering it is present.