21.5k views
5 votes
Consider the following program where the zu format specifier is used to display as an integer the result of sizeof. #include #include typedef union { int *i1; int *i2; }U; int main() { U temp; int i = 50; temp.i1 = &i; printf("%zu and %d\\", sizeof(temp), *(temp.i2)); return 0; } What is the output of the program above? Note in the choices below indicates output that isn't any of the literal values in the code above.

1 Answer

5 votes

Answer:

4 and 50

Step-by-step explanation:

To answer the question above, we are to first of all consider the size of union will be the max size of datatype in union data. I.E.

sizeof(int *) is 4 bytes

so, sizeof(U) = sizeof(temp) is 4

and we saved 50 in temp.i1. so, 50 we can access 50 from temp.i2 as well

so, output is 4 and 50

User Brodrigues
by
5.1k points