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; }

4th Nov 2016, 6:24 PM
zerin jawah
zerin jawah - avatar
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.
5th Nov 2016, 2:05 PM
kamal joshi
kamal joshi - avatar
+ 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.
4th Nov 2016, 6:46 PM
kamal joshi
kamal joshi - avatar
+ 1
final output = 3
4th Nov 2016, 6:53 PM
kamal joshi
kamal joshi - avatar
0
what is the final output result??
4th Nov 2016, 6:52 PM
zerin jawah
zerin jawah - avatar
0
thanks brother
4th Nov 2016, 6:54 PM
zerin jawah
zerin jawah - avatar
0
what does that '~' indicate before A()
5th Nov 2016, 2:02 PM
Laluprasad
Laluprasad - avatar
0
I think the program is not correct
5th Nov 2016, 10:41 PM
Samuel Frank
0
@samuel If you are pointing to syntax error "{", yeah, there is that problem. But I gave the answer considering it is present.
6th Nov 2016, 12:39 AM
kamal joshi
kamal joshi - avatar