0
0
Cprogramming~10 mins

Union basics - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a union named Data.

C
union [1] {
    int i;
    float f;
};
Drag options to blanks, or click blank then click option'
AData
BStruct
CVar
DType
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'struct' instead of 'union' keyword.
Forgetting to name the union.
Using variable names instead of the union name.
2fill in blank
medium

Complete the code to access the integer member of the union variable d.

C
union Data d;
d.[1] = 10;
Drag options to blanks, or click blank then click option'
Af
Bx
Ci
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using the float member name instead of the integer one.
Using undefined member names.
3fill in blank
hard

Fix the error in the union initialization.

C
union Data d = [1];
Drag options to blanks, or click blank then click option'
A{3.14}
B{.i = 3}
C{.f = 3.14}
D{i = 3}
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment inside braces without dot notation.
Initializing with the wrong member name.
4fill in blank
hard

Fill both blanks to create a union variable and assign a float value.

C
union Data [1];
[2].f = 5.5;
Drag options to blanks, or click blank then click option'
Ad
Bdata
Cvalue
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for declaration and access.
Using undefined variable names.
5fill in blank
hard

Fill all three blanks to create a union, declare a variable, and assign an integer value.

C
union [1] {
    int i;
    float f;
} [2];

[3].i = 42;
Drag options to blanks, or click blank then click option'
AData
Bd
Cvalue
Dnum
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in declaration and assignment.
Confusing union name with variable name.