Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone help me with this C++ questions? Please give an explanation for why a

ID: 3741308 • Letter: C

Question

Can anyone help me with this C++ questions? Please give an explanation for why as well as I am having trouble understanding.

1.) Which union variables will likely hold the correct value if used with the cout statement at the end of code? Select all that apply.

union ParkPass

{

bool unrestricted;

int visit_left;

float amount;

};

ParkPass MrEight;

MrEight.amount = 50.0;

MrEight.unrestricted = true;

MrEight.visit_left = 0;

cout << //MrEight variables

a.) amount

b.) unrestricted

c.) none of them

d.) visit_left

union ParkPass

{

bool unrestricted;

int visit_left;

float amount;

};

ParkPass MrEight;

MrEight.amount = 50.0;

MrEight.unrestricted = true;

MrEight.visit_left = 0;

cout << //MrEight variables

Possible Answers:

a.) amount

b.) unrestricted

c.) none of them

d.) visit_left

Explanation / Answer

Answer) vist_left

Explanation:- union is a special data type in C++ which can hold data of different data types. But at any time, only one member of the union will hold a correct value. So , in the program the last assignment operation to the union 'MrEight.visit_left = 0;' will store the value in visit_left variable and override the previous values holded by other variables

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote