Predict the output of following C++ program
(A) Compiler Error: union can’t have functions
(B) Compiler Error: can’t access private members of A
(D) garbage value
Explanation: Like struct and class, union can have methods. Like struct and unlike class, members of union are public by default.
Since data members of union share memory, the value of b becomes same as a.
Quiz of this Question