Basics of classes and Objects

Tell why the line no. 15 and 17 have different values of A.

hi @Gurjot you made an object t1 in main() and called the function for it. a and b refer to the data members of that object.
But you also declared an object t1 in the function itself. When you print t1.a, now this refers to the data member of a of the local object. Since this value has not been initialized yet, it is giving garbage value in output

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.