Skills101
← All practice quizzes

Quiz: Structures and Unions

5 questionsNo time limitPass: 60%+10 XP on first pass

Group related data with struct, use arrays of structures and pointers to structures (->), see struct padding vs union memory sharing in a picture, plus enum and typedef.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    If p is a pointer to a struct, how do you access its member age?

  2. Question 2

    What is the size of a union with members char, int and double (double = 8 bytes)?

  3. Question 3

    What does this print?

    #include <stdio.h>
    enum Color { RED, GREEN = 5, BLUE };
    int main(void) {
        printf("%d %d %d", RED, GREEN, BLUE);
        return 0;
    }
    
  4. Question 4

    Why can sizeof(struct) be bigger than the sum of its members?

  5. Question 5

    In a union, how many members hold a valid value at the same time?