C++ Programming - Objects and Classes - Discussion

Discussion Forum : Objects and Classes - Programs (Q.No. 4)
4.
What will be the output of the following program?
#include<iostream.h> 
class BixTeam
{
    int x, y; 
    public:
    BixTeam(int xx)
    {
        x = ++xx;
    }
    void Display()
    {
        cout<< --x << " ";
    }
};
int main()
{
    BixTeam objBT(45);
    objBT.Display();
    int *p = (int*)&objBT;
    *p = 23;
    objBT.Display();
    return 0; 
}
45 22
46 22
45 23
46 23
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
13 comments Page 2 of 2.

Swati said:   1 decade ago
What about 23?

Bharat said:   1 decade ago
Bro 45 is incremented by 1 in constructor definition, it becomes 46. And also we decrements by 1 when we display the value of x, that time it becomes 45.

Anonymous said:   1 decade ago
Why 45 is not incremented?


Post your comments here:

Your comments will be displayed after verification.