LearnFrenzy
Sign in Take a free test

Structures, Unions, Enums · Structures, Unions & Enums MCQ · Question 10

Anonymous unions and structs in C11 Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

In C11, a struct contains union { int i; float f; }; with no member name. How do you reach i for a variable v?

  • A v.union.i
  • B v.i Correct
  • C v->i
  • D It is not accessible
Correct Answer: Option B

Members of an anonymous union (or struct) are treated as members of the enclosing struct, so you write v.i. This was standardised in C11.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links