Suppose you need to keep a data struct with permission to access some resource based on the days of the week, but you can’t use a bool variable for each day. You need to use one bit per day of the week. Which of the following is a correct implementation of a structure with bit fields for this application?

Advertisement

  • A
    typedef struct {
    int sunday:1;
    int monday:1;
    // more days
    int friday:1;
    int saturday:1;
    } weekdays;
  • B
    typedef char[7]: weekdays;
  • C
    typedef struct {
    bit sunday:1;
    bit monday:1;
    // more days
    bit friday:1;
    bit saturday:1;
    } weekdays;
  • D
    typedef struct {
    bit sunday;
    bit monday;
    // more days
    bit friday;
    bit saturday;
    } weekdays;
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Leave a Comment


Share via
Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Send this to a friend