Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute CPA-21-02 Exam - Topic 2 Question 48 Discussion

Posted by Kris on Jan 05, 2026 at 05:16 AM

What is the output of the program?

#include

#include

using namespace std;

union t

{

char c;

int i;

};

class First

{

union t u;

public:

First() {

u.c = 'A';

}

void Print(){

cout << u.c;

}

};

int main()

{

First *t = new First();

t?>Print();

}

Suggested Answer: B

Get Premium CPA-21-02 Questions as Interactive Web-Based Practice Test or PDF Real Exam Format Detailed Explanations Instant Access Get Your Practice Test
27 comments · newest first
AR
Arlen 5 months ago
I believe it will compile fine. No errors.
LA
Layla 5 months ago
But what about the pointer syntax? Is it correct?
LA
Lashawn 5 months ago
Yeah, the constructor sets u.c to 'A'.
MA
Maurine 6 months ago
I think it prints: A.
TA
Tasia 6 months ago
How can it print both A and 65? That seems off.
CH
Charlene 6 months ago
I think it might throw a compilation error.
BE
Becky 6 months ago
Wait, isn't there a chance of a garbage value?
TI
Tijuana 6 months ago
Definitely B, no doubt!
LA
Layla 6 months ago
It prints: A
DO
Dominga 7 months ago
Lol, the program will probably just print a random garbage value. You can't trust unions!
DI
Dion 7 months ago
Haha, I bet the compiler will throw a fit and give us a compilation error. D all the way!
AL
Albina 7 months ago
Definitely B. The union will initialize the 'c' member to 'A'.
KE
Kenneth 8 months ago
Hmm, I'm not sure about this one. Could be B or C.
KI
Kimberlie 8 months ago
I'm pretty sure the answer is B. It prints 'A'.
IR
Irma 8 months ago
The output should be 'A'.
LA
Laurel 8 months ago
I feel like there might be a compilation error due to the way the Print function is called with the arrow operator.
BI
Billi 8 months ago
I practiced a similar question, and I think it should print 'A' because the Print function directly accesses the character.
DA
Danica 9 months ago
I'm not sure, but I remember something about unions that might cause a garbage value if not handled properly.
CO
Cordie 9 months ago
I think the output should be 'A' since the constructor initializes the union with 'A'.
BE
Beatriz 9 months ago
I've got it! The union will store the 'A' character, but when we print it, it will print the ASCII value 65 instead of just the character. The answer is C.
TY
Tyra 9 months ago
I'm not sure about this one. The question mentions "output of the program", so it might be related to how the program is executed, not just the union.
PA
Paulene 9 months ago
Okay, let me think this through. The union has a char and an int member, and the First class initializes the char member to 'A'. So the output should be just 'A'.
JO
Joesph 9 months ago
Hmm, I'm a bit confused about unions. Do they store multiple values at the same time or just one?
RO
Royce 10 months ago
I think I can handle this one. The key is understanding how unions work in C++.
JE
Jessenia 3 months ago
↳ replying to Royce
I think it might be a compilation error.
SA
Sabra 3 months ago
↳ replying to Royce
Unions can be tricky, but I agree with you.
DE
Denny 4 months ago
↳ replying to Royce
I believe it prints: A.
0/2000 characters

Save Cancel