LearnFrenzy
Sign in Take a free test

Structures, Unions, Enums · Exercise 1 of 4

Structures, Unions, Enums Structures, Unions & Enums MCQ

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twelve multiple-choice questions on structures, unions and enums – including padding, flexible array members, bit-fields, anonymous members (C11) and C23 enums. Pick an option to check your answer instantly.

Question 1 Easy

p is a pointer to a structure with a member x. Which expression is the same as p->x?

A *p.x
B (*p).x
C &p.x
D p.x
Question page & discussion
Question 2 Medium

On a typical 64-bit system, what is sizeof(struct { char c; int i; })?

A 5
B 8
C 6
D 16
Question page & discussion
Question 3 Easy

Given two variables a and b of the same struct type, which is true?

A a == b does not compile; compare the members (or write a function)
B a == b compares all members
C a == b compares their addresses
D a == b compares only the first member
Question page & discussion
Question 4 Easy

What is the size of a union?

A The sum of its members
B The size of its first member
C The size of its largest member, rounded up for alignment
D Always 8 bytes
Question page & discussion
Question 5 Easy

In enum { A, B = 5, C }; what is the value of C?

A 2
B 6
C 5
D 0
Question page & discussion
Question 6 Hard

Which statement about a flexible array member such as char data[]; is true?

A It must be the last member, and sizeof the struct does not include it
B It can appear anywhere in the struct
C It allocates memory automatically
D It can be the only member
Question page & discussion
Question 7 Medium

A struct has a member char *name pointing to heap memory. After b = a;, what is true?

A b gets its own copy of the name text
B b.name is set to NULL
C The assignment does not compile
D a.name and b.name point to the same text (a shallow copy)
Question page & discussion
Question 8 Easy

After typedef struct point Point;, which declaration is valid?

A struct Point p;
B typedef p;
C Point p;
D point p;
Question page & discussion
Question 9 Medium

Which is true about the bit-field unsigned ready : 1;?

A &s.ready gives its address
B It always occupies one byte
C Its address cannot be taken, because it may not start on a byte boundary
D It can be signed or unsigned with the same result
Question page & discussion
Question 10 Medium

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
C v->i
D It is not accessible
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links